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
Using CLI
- cd /path/to/my/repo
- git remote add origin ssh://git@bitbucket.org/<username>/<reponame>.git
- git push -u origin --all
Using SourceTree
- Repository>Add Remote...
- 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:
- In
Tools
>Options
, make sureSSH Client:
is set toPuTTY/Plink
under theGeneral
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
andSave 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.
No comments:
Post a Comment