(updated on 3-29-2019 to use the https instead of ssh, so you don't need to use ssh keys)
It seems like for BitBucket, you do have to create a repo online first. Using the instructions from Atlassian, simply create a new BitBucket repository, copy the repository url to the clipboard, and then add that repository as a new remote to your local repository (full steps below):
Get Repo URL
- in your BitBucket repo, choose "Clone" on the top-right
- choose "HTTPS" instead of "SSH" in the top-right of the dialog
- it should show your repo url in the form
git clone <repository url>
Add Remote Using CLI
cd /path/to/my/repo
git remote add origin https://bitbucket.org/<username>/<reponame>.git
git push -u origin --all
Add Remote Using SourceTree
- Repository>Add Remote...
- Paste the BitBucket repository url (
https://bitbucket.org/<username>/<reponame>.git
)
Old Method: Creating & Registering SSH Keys
(this method is if you use the ssh url instead of the https url, which looks like ssh://git@bitbucket.org/<username>/<reponame>.git
. I recommend just using https)
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:
- In
Tools
>Options
, make sure SSH Client:
is set to PuTTY/Plink
under the General
tab
- Select
Tools
>Create or Import SSH Keys
- In the popup window, click
Generate
and move your mouse around to give randomness to the key generator
You should get something like whats shown in the screenshot below. Copy the public key (highlighted in blue) to your clipboard
- 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
- Log in to your BitBucket account, and on the top right, click your profile picture and click
Settings
- Go to the
SSH Keys
tab on the left sidebar
- 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.
Sidenote: Creating SSH Keys using CLI
Just follow this tutorial
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…