Thanks to my good friend Simon I've been a happy git user for a few months now. I installed my own git server on Amazon EC2 using Ubuntu, git and gitolite and just fired it up once or twice a day to push and pull. This worked out fine but with more and more easy to use git hosting services springing up I gave Atlassian's bitbucket a try since it offers unlimited private repositories which is a bonus.
It took me a little while to figure out how to move my existing repository into bitbucket, especially since it was already tracking the existing remote repo on my server. What follows are a few easy steps that describe the process -
1) Create a new bitbucket repo
Yes, I did not import my existing repo since I could not figure out how to do that. I connect via ssh to my git server yet bitbucket asks for a username andpassword when importing repos that require authentication. Maybe there's a way to do it, but I did not waste any more time on it, and the way outlined here also keeps your project history in tact, and it's simple.
Once you created the new, empty repo on bitbucket simply leave that page open, we'll come back to it in step 3.
2) Detach your existing local git repo from its remote
I'm on OSX so I used Terminal to cd into my local project folder:
You can tell git to show you the remote aliases for your project:
To see the actual URL for each alias use
I then detached my existing remote from the local repo:
Back onto the bitbucket website where you still have the page open. You did leave it open, right? If you didn't then find the option I mention below, or just nuke the project and create it again.
There's a big fat 'I have code I want to import' showing under 'Add some code'. Click it.

Simples. Bitbucket shows you the exact code you need to enter into Terminal to add your project to the new repo. It looks something like this:
2$ git remote add origin ssh://git@bitbucket.org/username/myproject.git
3$ git push -u origin master # to push changes for the first time
You're done. If you think I'm out of my mind or have overlooked something then please feel free to have a moan in the comments. Or thank me if it helps :-)


#1 by mathias on 8/24/12 - 9:02 PM
#2 by fiona on 9/20/12 - 8:00 PM
#3 by Jared on 9/26/12 - 3:31 PM
#4 by Sarath on 11/1/12 - 1:01 AM
#5 by biogetica on 11/7/12 - 7:30 AM
and thanks it just worked out perfectly.
#6 by ruen on 12/3/12 - 9:34 AM
#7 by Sameer Kohli on 2/5/13 - 4:49 AM
#8 by Paul on 2/23/13 - 12:12 PM
I only just discovered bitbucket allows free private repositories, which was the only reason I was paying github $84 a year.
bye bye github
#9 by Stefan Richter on 2/23/13 - 12:45 PM
#10 by david on 2/26/13 - 4:20 PM