For example, will the following work?
[branch "mybranch"]
remote = myremote
merge = refs/heads/mybranch
[branch "mybranch"]
remote = yourremote
merge = refs/heads/mybranch
No. Git configuration files are flexible enough to support this, though there's no need for a second section. That is, you can write this more simply as:
[branch "mybranch"]
remote = myremote
remote = yourremote
merge = refs/heads/mybranch
but only a few parts of Git make any use of multiple settings.1 The git push
command in particular decides whether you've specified a remote, and if you have not, it gets the last setting for branch.branch.remote
(where branch
is the current branch). Then it decides whether you've specified a refspec, and if not, uses your push.default
setting to decide how to ask the other Git to update one of its names based on your branch
's current commit. So:
- if you specify a
remote
argument, the two remote settings are irrelevant;
- if not, Git takes the last one.
This means that all settings except for the last become irrelevant.
(There are ways to use triangular workflows, where you fetch from one repository but push to another, but this is not one. Use google search to find some.)
1The git fetch
command is one that does make use of multiple settings: it takes all of the fetch = ...
settings for any given remote, when it is doing a defaulted git fetch
. That is:
[remote "origin"]
fetch = +refs/heads/master:refs/remotes/origin/master
fetch = +refs/heads/develop:refs/remotes/origin/develop
produces a repository that acts a lot like like a single-branch clone, except that it's what we might call a two-branch clone.