git-config 的手册页列出了 push.default 的这些选项:
nothing - do not push anything.
matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
upstream - push the current branch to its upstream branch.
tracking - deprecated synonym for upstream.
current - push the current branch to a branch of the same name.
在大多数情况下,我假设推送到分支的上游分支与推送到同名分支是一样的,因为上游分支通常具有相同的名称,并且由于同名分支( “current”)通常(或者总是,根据定义?)在上游。那有什么区别呢?
更新:The man page for git-config已经更新(正如人们所期望的那样),因此进行了区分there现在可能更清楚了。
最佳答案
您已经总结了问题中的差异。 upstream
推送到 configured 上游分支,而 current
假定上游分支与 current 本地分支同名分支,并推送到该特定名称。实际上,没有理由假设本地分支的上游跟踪分支与本地分支本身同名。
例如,如果您在多个存储库或跨多个共享开发人员远程工作,您通常最终会跟踪同一分支的不同分支,例如 allen-master
或 susan-master
,它们分别跟踪 Allen 和 Susan 的存储库中的 master
分支。在这种情况下,current
将是不正确的设置,因为这些分支名称在它们的 Remote 上不存在。然而,upstream
会工作得很好。
一个更实际的例子可能是跟踪 development
和 production
存储库。您的工作流可能会为每个分支使用不同的主线分支,但这可能会造成混淆。假设您是一名代码集成商,并希望分别跟踪两个存储库的 master
分支。
git checkout -b production --track production/master
git checkout -b development --track development/master
现在您有两个分支跟踪各自的存储库,它们都根本不使用 master
命名约定。分支名称几乎没有混淆:它们明确描述了它们跟踪的内容。然而,push.default = current
没有任何意义,因为远程不包含 development
或 production
分支。
关于git - git push.default=current 和 push.default=upstream 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11872984/