The short: is there a way to have a git repo push to and pull from a list of remote repos (rather than a single "origin")?
The long: I often have a situation when I'm developing an app in multiple computers, with different connectivity -- say a laptop while on transit, a computer "A" while I'm in a certain location, and another computer "B" while on another. Also, the laptop might have connectivity with only either "A" or "B", and sometimes both.
What I would like to is for git to always "pull" from and "push" to all the computers it can currently connect to, so it's easier to jump from one machine to the other and continue working seamlessly.
I added two separate pushurl to the remote "origin" in the .git congfig file. When I run
git push origin "branchName"
Then it will run through and push to each url. Not sure if there is an easier way to accomplish this but this works for myself to push to Github source code and to push to My.visualStudio source code at the same time.Adding the
all
remote gets a bit tedious as you have to setup on each machine that you use.Also, the
bash
andgit
aliases provided all assume that you have will push to all remotes. (Ex: I have a fork ofsshag
that I maintain on github and gitlab. I have the upstream remote added, but I don't have permission to push to it.)Here is a
git
alias that only pushes to remotes with a push url that includes@
.psall = "!f() { \ for R in $(git remote -v | awk '/@.*push/ { print $1 }'); do \ git push $R $1; \ done \ }; f"
The latest version of git (as of October 2012) allows you to do this from the command line:
Then
git push
will push to user1@repo1, then push to user2@repo2. Leave out--push
if you also want to be able togit pull
from them too.For updating the remotes (i.e. the
pull
case), things have become easier.The statement of Linus
in the referenced entry at the Git mailing list in elliottcable's answer is no longer true.
git fetch
learned the--all
parameter somewhere in the past allowing to fetch all remotes in one go.If not all are requested, one could use the
--multiple
switch in order to specify multiple remotes or a group.I took the liberty to expand the answer from nona-urbiz; just add this to your ~/.bashrc:
Usage:
If you do not provide any branch argument for git-pullall then the pull from non-default remotes will fail; left this behavior as it is, since it's analogous to git.
I added these aliases to my ~/.bashrc: