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.
5 comments:
$ eval $(ssh-agent)
$ ssh-add
Now you only add your password once. Depending on your distro you may already have ssh-agent loaded, so first try just a straight:
$ ssh-add
Use an ssh agent to remember your key.
Great post!
"(where origin is name of your branch)": this may be wrong. master is name of branch, while origin is name of the remote.
Great post!
"(where origin is name of your branch)" may be wrong. origin is the name of a remote, master is name of your branch.
Thanks Shengbin, corrected that now
Post a Comment