具有多个本地跟踪分支的远程分支
一个远程分支是否可以有多个本地跟踪分支?或者这会混淆推/拉命令吗?
Is it possible, that a remote branch can have multiple local tracking branches? Or would that confuse the push/pull commands?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点好。
Git 查找给定本地分支的远程信息,而不是相反。也就是说,远程分支没有多个本地跟踪分支。多个本地分支具有相同的远程跟踪分支。
当您拉取时,它会获取适当的远程分支,更新相应的远程跟踪分支,然后合并它。一切都会好起来的;仅涉及一个分支及其跟踪分支。我怀疑这是你的真实用例。
当您推送时,通常根本不会使用跟踪信息。
push.default
的默认设置是matching
,即将本地分支推送到同名的远程分支。在这种情况下,一切都会好起来,平淡无奇。但是,如果您将
push.default
设置为tracking
,它会再次为每个本地分支查找正确的远程分支 - 但如果您的本地分支不是一样的,显然不可能全部都推到那里去!如果您正在考虑多个本地分支跟踪同一个远程分支,那么您可能根本不想将push.default
设置为跟踪。It's fine, sort of.
Git looks up remote information for given local branches, not the other way around. That is, the remote branch doesn't have multiple local tracking branches. Multiple local branches have the same remote tracking branch.
When you pull, it fetches the appropriate remote branch, updates the corresponding remote tracking branch, and merges it. Everything will go just fine; only that one branch and its tracked branch are involved. I suspect this is your real use case.
When you push, normally tracking information isn't used at all. The default setting of
push.default
ismatching
, i.e. push local branches to remote branches of the same name. In this case, everything will still be fine, trivially so.However, if you've set
push.default
totracking
, it'll again look up the right remote branch for each local one - but if your local branches aren't identical, they obviously can't all be pushed there! Probably if you're thinking about multiple local branches tracking the same remote, you simply don't want to setpush.default
to tracking.就不会有混乱了。如果有的话,这取决于您以及您对 DAG、分支和远程工作方式的理解程度。 :)
there would be no confusion. If anything, it depends on you and how well you understand the way the DAG, branches and remotes work. :)