multiple git remotes

I would like to manage a project across multiple remote git repositories, specifically, a public github repository and my own private repositories.

Fortunately, git supports as many remote repositories as you need. When you clone a repository, there will be a default remote called “origin”, i.e.,

$ git clone
$ cd dotfiles
$ git remote -v
origin (fetch)
origin (push)

Adding additional remotes is trivial, i.e.,

$ git remote add bob
$ git remote add ann
$ git remote add pat

Now, when we look at the remotes for our repository we’ll see the new entries,

$ git remote -v
origin (fetch)
origin (push)
bob (fetch)
bob (push)
ann (fetch)
ann (push)
pat (fetch)
pat (push)

If we want to pull from Ann’s repository and merge it into our local master branch,

$ git pull ann master

And then if we wanted to push those changes to Bob’s repository,

$ git push bob master

We can also rename and remove remotes, i.e.,

$ git remote rename bob bobbie
$ git remote remove bobbie

In practice, we may not want to be constantly merging everything into a local master, instead, we may want to investigate the code before any merges. This can be done easily. I prefer to use tracked branches, as follows,

$ git checkout -b bob-master
$ git remote add bob
$ git fetch bob master
$ git --set-upstream-to=bob/master

We can now inspect the bob-master branch and merge manually as we see fit,

$ git checkout bob-master
$ git pull
$ git checkout master
$ git diff bob-master