11 January 2016

How to : Import Local git Repo to SourceTree then Push Bitbucket

Hello, I will documented my problem, how to import local git repo to SourceTree then push to BitBucket account. There are two ways :

Using CLI
  1. cd /path/to/my/repo
  2. git remote add origin ssh://git@bitbucket.org/<username>/<reponame>.git
  3. git push -u origin --all

Using SourceTree


  1. Repository>Add Remote...
  2. Paste the BitBucket repository url (git@bitbucket.org/<username>/<reponame>.git)

UPDATE: Creating & Registering SSH Keys

BitBucket is great for private repos, but you'll need to set up an ssh key to authorize your computer to work with your BitBucket account. Luckily Sourcetree makes it relatively simple:

Creating a Key In SourceTree:

  1. In Tools>Options, make sure SSH Client: is set to PuTTY/Plink under the General tab
  2. Select Tools>Create or Import SSH Keys
  3. In the popup window, click Generate and move your mouse around to give randomness to the key generator
  4. You should get something like whats shown in the screenshot below. Copy the public key (highlighted in blue) to your clipboard
    putty
  5. Click Save private Key and Save public key to save your keys to wherever you choose (e.g. to <Home Dir>/putty/ssk-key.ppk and <Home Dir>/putty/ssh-key.pub respectively) before moving on to the next section
Registering The Key In BitBucket
  1. Log in to your BitBucket account, and on the top right, click your profile picture and click Settings
  2. Go to the SSH Keys tab on the left sidebar
  3. Click Add SSH Key, give it a name, and paste the public key you copied in step 4 of the previous section
That's it! You should now be able to push/pull to your BitBucket private repos. Your keys aren't just for Git either, many services use ssh keys to identify users, and the best part is you only need one. If you ever lose your keys (e.g. when changing computers), just follow the steps to create and register a new one.

No comments: