简体   繁体   English

远程跟踪分支和远程分支之间有什么区别?

[英]What is the difference between a remote tracking branch, and a branch on a remote?

It seems that I can pull from, or push to, a branch on a remote repository, from/to the branch that I am working on. 似乎我可以从远程存储库中拉出或推送到一个分支,从/到我正在处理的分支。 If so, then what is the purpose of a remote tracking branch? 如果是这样,那么远程跟踪分支的目的是什么?

Is it solely for the purpose of checking out the branch and seeing what it looks like? 它只是为了检查分支并看到它的样子吗? It appears that a remote tracking branch is like a mirror to a branch on a remote. 看起来远程跟踪分支就像是远程分支的镜像。

FYI: I'm fairly new to git, but have read and re-read many tutorials, but I am still no more clear on this point! 仅供参考:我对git很新,但已阅读并重新阅读了许多教程,但我仍然不清楚这一点!

Thanks! 谢谢!

You're right - remote branches do indeed mirror branches in the remote repository. 你是对的 - 远程分支确实在远程存储库中镜像分支。

Remote branch and remote tracking branch both are used to refer to a branch of the form refs/remotes/<remote-name>/<branch-name> , reported eg as origin/master . 远程分支和远程跟踪分支都用于引用格式refs/remotes/<remote-name>/<branch-name> ,例如作为origin/master (Note that this is sometimes confused with the notion of a branch which is tracking a remote branch, eg your master branch is associated with origin/master. The terminology is unfortunate, but there we are.) (请注意,这有时会与跟踪远程分支的分支的概念混淆,例如,您的主分支与origin / master关联。术语很不幸,但我们确实如此。)

The purpose of a remote tracking branch is to remember the last known position of the branch in the remote repository. 远程跟踪分支的目的是记住远程存储库中分支的最后已知位置。 This is necessary in order for git pull to work; 这对于git pull工作是必要的; it fetches from the branch on the remote (origin's master branch), stores that in the remote tracking branch ( origin/master ), and then merges that locally. 它从远程(原始主分支)上的分支获取,将其存储在远程跟踪分支( origin/master )中,然后在本地进行合并。 Commits can only be created locally, and merges can only be done in a work tree, so this is completely essential! 提交只能在本地创建,合并只能在工作树中完成,所以这是完全必要的!

The remote tracking branch is also useful, as you mention, for examination of what's going on in the remote repository. 如您所述,远程跟踪分支对于检查远程存储库中发生的情况也很有用。 By default there are remote branches for all of the remote's branches, so you can easily use git remote update [--prune] <remote> or git fetch <remote> to update them, and then check them out and play with them as you like. 默认情况下, 所有远程分支都有远程分支,因此您可以轻松使用git remote update [--prune] <remote>git fetch <remote>来更新它们,然后检查它们并在它们中播放它们喜欢。 Note that you can do things besides check them out - you can diff against them ( git diff origin/master ), find out what commits origin has that you don't ( git log master..origin/master ), or anything else you like. 请注意,您可以执行除了检查之外的事情 - 您可以对它们进行git diff origin/mastergit diff origin/master ),找出您没有的提交源( git log master..origin/master ),或者其他任何你喜欢。 Since all examinations of history are local, the remote branch has to be there for you to use. 由于所有历史考试都是本地的,因此远程分支必须在那里供您使用。

Since git push affects branches in the remote, it naturally updates your remote tracking branches; 由于git push影响远程分支,它自然会更新远程跟踪分支; it wouldn't be very intelligent to change origin's master then pretend it was still in the old position until you fetched! 改变原点的主人然后假装它仍然处于旧位置直到你拿到它是不是很聪明! But it doesn't actually depend on the remote tracking branches. 但它实际上并不依赖于远程跟踪分支。 (If you set push.default to tracking, it will use your tracking configuration, eg master tracking origin's master, to decide what to push. But it still doesn't actually depend on the remote tracking branch.) (如果设置push.default到跟踪, 它将使用您的跟踪配置,如主跟踪出身的主人,来决定推什么,但它仍然没有真正依赖于远程跟踪分支)。

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

相关问题 上游分支机构和远程跟踪分支机构之间有什么区别? - What is difference between a upstream branch and remote tracking branch? 本地分支、本地跟踪分支、远程分支和远程跟踪分支有什么区别? - What are the differences between local branch, local tracking branch, remote branch and remote tracking branch? Git命令:git checkout -b和有什么不一样 <branch><remote branch> 和git分支 <branch><remote branch> ? - Git command: what is the difference between git checkout -b <branch> <remote branch> and git branch <branch> <remote branch>? GIT 中本地、远程和远程跟踪分支之间的区别 - DIfference between local , remote and remote tracking branch in GIT 什么是本地分支,远程跟踪本地分支,远程分支 - What are local branch,remote tracking local branch, remote branch GIT中的分支和远程有什么区别? - What is the difference between Branch and Remote in GIT? Git远程分支跟踪 - Git Remote Branch tracking Git跟踪远程分支 - Git tracking remote branch 在git中checkout远程分支和pull远程分支之间的区别? - Difference between checkout remote branch and pull remote branch in git? “ git push remote branch”和“ git push remote HEAD:branch”之间有什么区别? - What is the difference between “git push remote branch” and “git push remote HEAD:branch”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM