[英]How to set default upstream for a new branch in git?
I'd like to set the default upstream branch of any branch I create locally to be origin/main
. 我想将我在本地创建的任何分支的默认上游分支设置为
origin/main
。
This is mainly for pull --rebase
, since we never push to remote (only through a code review process). 这主要用于
pull --rebase
,因为我们从不推送到远程(仅通过代码审查过程)。
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. 没关系(我有一个Bash别名为我做这件事),但是我想知道是否可以将git的config设置为自动完成。
So far I looked through the git-config
documentation and StackOverflow questions but haven't found a solution. 到目前为止,我浏览了
git-config
文档和StackOverflow问题,但没有找到解决方案。
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. 您可以将
branch.autoSetupMerge
选项设置为true
以使Git为从远程引用创建的分支自动启用--track
(相当于设置上游)。
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
. 但是,
true
实际上是此设置的默认值-您可能看不到它的效果的原因是因为您实际上是在创建从main
的本地副本开始的分支。
If you create your branches with something like: 如果您使用以下方式创建分支:
git checkout -b new-branch-name origin/main`
Then then would automatically track origin/main
. 然后会自动跟踪
origin/main
。
您可以使用检出后挂钩设置上游分支https://schacon.github.io/git/githooks.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.