简体   繁体   English

git 中的新分支默认跳过 --set-upstream

[英]skipping --set-upstream by default for new branch in git

my workflow currently after checkout -b <new_branch> from master, I will push to <new_branch>, but one thing annoy me is that git force me to do我的工作流程目前在从 master 结帐 -b <new_branch> 之后,我将推送到 <new_branch>,但让我烦恼的一件事是 git 强迫我做

git push --set-upstream origin <new_branch>

how can I skip it by default?我如何默认跳过它? I don't see the point of doing that.我看不出这样做的意义。

From the Git Push.Default Documentation,来自 Git Push.Default文档,

Defines the action git push should take if no refspec is given (whether from the command-line, config, or elsewhere).如果没有给出 refspec(无论是从命令行、配置还是其他地方),定义 git 推送应该采取的操作。 Different values are well-suited for specific workflows;不同的值非常适合特定的工作流程; for instance, in a purely central workflow (ie the fetch source is equal to the push destination), upstream is probably what you want.例如,在纯粹的中央工作流程中(即获取源等于推送目标),上游可能是您想要的。 Possible values are:可能的值为:

nothing - do not push anything (error out) unless a refspec is given. nothing - 除非给出 refspec,否则不要推送任何内容(错误输出)。 This is primarily meant for people who want to avoid mistakes by always being explicit.这主要适用于希望通过始终明确来避免错误的人。

current - push the current branch to update a branch with the same name on the receiving end. current - 推送当前分支以更新接收端同名的分支。 Works in both central and non-central workflows.适用于中央和非中央工作流程。

upstream - push the current branch back to the branch whose changes are usually integrated into the current branch (which is called @{upstream}). upstream - 将当前分支推回其更改通常集成到当前分支的分支(称为@{upstream})。 This mode only makes sense if you are pushing to the same repository you would normally pull from (ie central workflow).仅当您推送到您通常会从中提取的同一存储库(即中央工作流程)时,此模式才有意义。

simple - in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch's name is different from the local one. simple - 在集中式工作流程中,如果上游分支的名称与本地分支的名称不同,则可以像上游一样工作,并增加安全性以拒绝推送。

So you can do below and set it to所以你可以在下面做并将其设置为

git config --global push.default current git config --global push.default current

In any case you have to push your new branch to the remote repo, but to make things shorter you can do following:在任何情况下,您都必须将新分支推送到远程仓库,但为了缩短时间,您可以执行以下操作:

  • git push -u origin <new_branch> (instead of --set-upstream) git push -u origin <new_branch> (而不是--set-upstream)
  • git push -u origin HEAD Pushing to HEAD is equivalent to pushing to a remote branch having the same name as your current branch git push -u origin HEAD推送到 HEAD 相当于推送到与当前分支同名的远程分支
  • You also can create an alias for this commands, to do so check this out: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases您还可以为此命令创建别名,请查看: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases

Starting with git 2.37.0, you can run this command once, in order to avoid having to specify ``--set-upstream`:从 git 2.37.0 开始,您可以运行一次此命令,以避免必须指定 --set-upstream :

git config --global --add --bool push.autoSetupRemote true

From the documentation :文档中:

If set to "true" assume --set-upstream on default push when no upstream tracking exists for the current branch;如果设置为“true”,则当当前分支不存在上游跟踪时,默认推送时假定 --set-upstream; this option takes effect with push.default options simple, upstream, and current.此选项对 push.default 选项 simple、upstream 和 current 生效。 It is useful if by default you want new branches to be pushed to the default remote (like the behavior of push.default=current) and you also want the upstream tracking to be set.如果默认情况下您希望将新分支推送到默认远程(如 push.default=current 的行为)并且您还希望设置上游跟踪,这很有用。 Workflows most likely to benefit from this option are simple central workflows where all branches are expected to have the same name on the remote.最有可能从此选项中受益的工作流程是简单的中央工作流程,其中所有分支都应在远程具有相同的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM