1

Example: I have a local branch called mybranch

I want it to fetch from one remote branch: remoteToFetch/branchToFetch

And I want it to push to another remote branch: remoteToPush/branchToPush

So when I do git fetch and git push (on that branch mybranch), it fetches and pushes from and to that different references, by default.

remoteToFetch/          remoteToPush/
branchToFetch           branchToPush
     \                 /
      \               / 
    git fetch     git push
        \           /
         \         /
           mybranch

Is there a way to do that?

OBS:

I know this solution, but it seems to change all default pushes to one remote only, which is not what I want.

Diogo
  • 590
  • 6
  • 23

1 Answers1

1
git config branch.mybranch.remote remoteToFetch
git config branch.mybranch.pushRemote remoteToPush

See the docs on branch.mybranch.remote and pushRemote.

git config branch.mybranch.merge refs/heads/branchToFetch defines the upstream branch. Unfortunately there can be only one upstream branch, you cannot define one branch to fetch and another to push. The docs.

For push try to set remote.remoteToPush.push:

git config remote.remoteToPush.push refs/heads/mybranch:refs/remotes/remoteToPush/branchToPush
phd
  • 82,685
  • 13
  • 120
  • 165
  • Thankyou @phd. Just to make the answer more complete: what if I want to specify the default remote branches? I mean: `branchToFetch` and `branchToPush` on the remotes. They don't appear in the command. – Diogo Dec 10 '22 at 12:30