14

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.

Arafangion
  • 11,517
  • 1
  • 40
  • 72
  • possible duplicate of [pull/push from multiple remote locations](http://stackoverflow.com/questions/849308/pull-push-from-multiple-remote-locations) – RedX Nov 06 '13 at 09:25

2 Answers2

12

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...

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • What kind of alias would you recommend? I suppose that the most reasonable constraints would be that we only need consider the fast-forward case - anything else should cause the command to fail, forcing me to pull each remote individually. – Arafangion Nov 26 '10 at 09:50
  • @Arafangion: initially, I though about a naive alias like `git config --global alias.pullall "!git pull origin1 && git pull origin2"`. However, the `receive.denyNonFastForwards` config is for push, not pull... – VonC Nov 26 '10 at 09:56
  • Looks like I may just need to hack up a quick shell script to do the work, then, pulling each remote until an in-progress-merge is detected. – Arafangion Nov 26 '10 at 10:16
  • 2
    @Arafangion: true but you will need to take into account the case where the first pull works, and the second don't: a full reset to before the *first* pull will be needed. – VonC Nov 26 '10 at 12:29
1

I have written a script that may help with this:

git-list-upstream-commits

It won't do any pulling or merging, but it will look at all the remote branches, and show you which ones have commits which you do not have on your current branch.

It sorts the branches with the most recent commits at the bottom, and it shows the latest commit on each branch, with some basic info.

Example of using the script

joeytwiddle
  • 29,306
  • 13
  • 121
  • 110