I'd like to set the default upstream branch of any branch I create locally to be origin/main
.
This is mainly for pull --rebase
, since we never push to remote (only through a code review process).
Right now I achieve this by:
$ git checkout -b some-new-branch-name
$ git branch --set-upstream-to=origin/main
It's OK (I have a Bash alias to do that for me), but I was wondering whether I can set git's config to do that automatically.
So far I looked through the git-config
documentation and StackOverflow questions but haven't found a solution.
Is this possible?
You can set the branch.autoSetupMerge
option to true
to have Git automatically enable --track
(which is equivalent to setting the upstream) for branches that are created from remote refs.
However, true
is actually the default value for this setting - the reason you're likely not seeing its effect is because you're actually creating branches that start from the local copy of main
.
If you create your branches with something like:
git checkout -b new-branch-name origin/main`
Then then would automatically track origin/main
.
您可以使用检出后挂钩设置上游分支https://schacon.github.io/git/githooks.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.