timakro timakro - 1 year ago 74
Git Question

Different default push and pull remotes for all branches

For all existing branches in my local repository and new branches I create in my local repository pulling should by default pull from the

remote and pushing should by default push to the

Answer Source

When you create a new branch in git it doesn't have a "default remote" until you assign one (using, e.g., git push --set-upstream or git branch --set-upstream-to).

A remote can have different push and pull URLs, so you could do something like:

git remote add myremote https://gitserver/for/origin
git remote set-url --push https://otherserver/for/timakro

Now if you create a new branch:

git checkout -b my_feature_branch

And set the upstream:

git branch --set-upstream-to myremote

Then git pull on this branch will pull from the first url, and git push will push to the second.

You can make the same change for all existing branches in your repository through the use of a simple shell script to iterate over your local branches and run git branch --set-upstream-to. Maybe something like:

git for-each-ref refs/heads/ |
  awk -F'\t' '{print $2}' |
  xargs -n1 git branch --set-upstream-to myremote
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download