If you already have a repository, you can view it in SourceTree. Click New, then Add Existing Local Repository. Select the repository your wish to add, then click Open. Your added repository appears under Local.
(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
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
https://bitbucket.org/<username>/<reponame>.git
)(this method is if you use the ssh url instead of the https url, which looks like ssh://[email protected]/<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:
Tools
>Options
, make sure SSH Client:
is set to PuTTY/Plink
under the General
tabTools
>Create or Import SSH Keys
Generate
and move your mouse around to give randomness to the key generatorYou should get something like whats shown in the screenshot below. Copy the public key (highlighted in blue) to your clipboard
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 sectionRegistering The Key In BitBucket
Settings
SSH Keys
tab on the left sidebarAdd SSH Key
, give it a name, and paste the public key you copied in step 4 of the previous sectionThat'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
Actually there is a more simple solution (only on Mac version). Just four steps:
As this video illustrates, creating a repo online first is the usual way to go.
The SourceTree Release Notes do mention for SourceTree 1.5+:
Support creating new repositories under team / organisation accounts in Bitbucket.
So while there is no "publishing" feature, you could create your online repo from SourceTree.
The blog post "SourceTree for Windows 1.2 is here" (Sept 2013) also mention:
Now you can configure your Bitbucket, Stash and GitHub accounts in SourceTree and instantly see all your repositories on those services. Easily clone them, open the project on the web, and even create new repositories on the remote service without ever leaving SourceTree.
You’ll find it in the menu under View > Show Hosted Repositories, or using the new button at the bottom right of the bookmarks panel.
I used this and it worked out well for me. If your directory is
"repo" and your project is "hello" copy the project there
cd /path/to/my/repo
Initialize your directory
git init
Stage the project
git add hello
commit the project
git commit
Add configurations using the email and username you are using in Bitbucket
git config --global user.email
git config --global user.name
Add comment to the project
git commit -m 'comment'
push the project now
git push origin master
Check out of the master
git checkout master
Bitbucket supports a REST API you can use to programmatically create Bitbucket repositories.
Documentation and cURL sample available here: https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html#repositoryResource-POSTanewrepository
$ curl -X POST -v -u username:password -H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/teamsinspace/new-repository4 \
-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }'
Under Windows, curl is available from the Git Bash shell.
Using this method you could easily create a script to import many repos from a local git server to Bitbucket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With