Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

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.

In 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")?

1 Answer

0 votes
by (50.2k points)

You can configure multiple remote repos using git remote command:

git remote add alt alt-machine:/path/to/repo

To fetch from configured remotes (but not merge into HEAD) do:

git remote update

If you are not connected to one of the remotes it will throw you an error which you need to fix it manually with a merge or cherry-pick depending on how you want to make changes.

To fetch the master branch from alt and pull it into your current head, do:

git pull alt master

In fact, git pull is almost shorthand for git pull origin HEAD. 

Thus you can pull or push from multiple locations.

Browse Categories