Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track more than one remote with a given branch using Git?

Tags:

git

The situation is this:

I have more than one remote repository - for reference, lets say that one is the "alpha" repository, and we have recently set up a new "beta" repository, which some users have migrated to.

Both repositories have a "master" branch.

How do I set up my local master such that it will attempt to automatically push and pull to and from both the alpha and beta repositories, without manually specifying the remote I want to use each time?

I should elaborate that I don't want to set up two local branches 'master-alpha' and 'master-beta', I want the same local branch to track both remotes.

like image 348
Arafangion Avatar asked Nov 26 '10 04:11

Arafangion


People also ask

Can you have multiple remotes git?

Add remotes using git remoteYou can set multiple remote URLs to a single remote using git remote. If you don't have a remote named 'all' already, create it using git remote add then use git remote set-url --add to add a new URL to the existing remote. You can cross-check added new remotes using git remote -v .

Which command can be used to track a remote branch?

The command git branch -f --track $BRANCH origin/$BRANCH does the trick.


1 Answers

I don't think it is possible with one git command.
The other alternative would be to define a git alias which would git pull master from one repo, and then git pull master from the other.

But if the history of commits differ too greatly between the two master, that would quickly lead to a massive number of conflicts...

like image 67
VonC Avatar answered Oct 11 '22 00:10

VonC