Now that BitBucket supports Git, I’ve been utilizing both GitHub and BitBucket for my project hosting, and have been looking into migrating to BitBucket for my private repositories (as they are free). This is part of the beauty of using a distributed version control system, you can have your code in multiple locations, rather than one central Subversion server.
In Git, I could add two remotes and each time I want to push/pull code I would type something like:
git push github master
git push bitbucket master
However, I want to make things as easy as possible for myself, and I’m simply using these two repositories as a mirror of each other, so I’ll be telling git to push to multiple URL’s with the same remote.
To do this, I need to edit the .git/config file for my project. You can navigate here via the command line, or in Windows you can turn on hidden file display and open the .git folder in Windows Explorer
In this file, I’ve already added one of my remotes using the git remote add command, as you can see here:
To make it push to BitBucket at the same time as GitHub, you simply duplicate this URL line and add the BitBucket URL to it
Then if you do a git push origin master (where master is name of your branch), you will see it will push to these URLs in succession:
Unfortunately if you have a password protected ssh key it will still ask twice for your password.
Now each time you push to your origin remote, you’ll be taking full advantage of gits distributed nature, and will have two remote copies of your code.