简体   繁体   English

什么是本地分支,远程跟踪本地分支,远程分支

[英]What are local branch,remote tracking local branch, remote branch

I have started working with Git recently. 我最近开始与Git合作。 Normally I use eclipse Egit and very rarely git shell. 通常我使用Eclipse Egit,很少使用git shell。 After going through a lot of material on Git and its branching, I still have confusion regarding that. 在讨论了有关Git及其分支的大量材料之后,我对此仍然感到困惑。

I know there are n number questions on Stack Overflow on the same topic but so far I have only either added to my confusion or I have got half baked knowledge on branching. 我知道关于同一主题的Stack Overflow上没有n个问题,但到目前为止,我只是加深了困惑,或者对分支有了半熟的知识。 So I am putting the n + 1st question on this regarding my understanding. 因此,关于我的理解,我要提出第n + 1个问题。

Can somebody confirm if my understanding is correct: 有人可以确认我的理解是否正确:

  1. There are two types of branches: Local and Remote where local branches are branches on local repositories and Remote branches are on Remote Repositories 有两种类型的分支:本地和远程,其中本地分支是本地存储库上的分支,而远程分支位于远程存储库上
  2. There is third type of branch called Remote Tracking branch which automatically adjusts its head to match with the branch its tracking whenever we fetch the changes from remote branch. 第三种类型的分支称为“远程跟踪”分支,每当我们从远程分支中获取更改时,它都会自动调整其头部以使其与分支的跟踪相匹配。
  3. So a branch can only track some remote branch and not any local branch. 因此,分支只能跟踪某个远程分支,而不能跟踪任何本地分支。 Is this correct? 这个对吗?
  4. When I clone a remote repository two types of branches are created automatically as follows: 克隆远程存储库时,会自动创建两种类型的分支,如下所示:
    1. Local branch called as master. 本地分支称为主节点。
    2. A Local Remote tracking branch which tracks the remote repository's master branch. 本地远程跟踪分支,它跟踪远程存储库的主分支。
  5. Can my local master branch (mentioned in 4.1 above) track Remote tracking branch created on local (mentioned in 4.2)? 我的本地主分支(在上文4.1中提到)可以跟踪在本地(在4.2中提到)中创建的远程跟踪分支吗?
  6. If yes I guess it is automatically set to track this branch and thats why I don't have to do anything special to fetch /push the changes to remote repository from my working directory right? 如果是的话,我想它会自动设置为跟踪该分支,这就是为什么我不必做任何特殊的事情就可以从我的工作目录中获取/将更改推送到远程存储库的原因? So when I fetch the changes using Eclipse's Team synchronizing following things happen 因此,当我使用Eclipse的团队来获取更改时,会发生以下情况
    1. Changes in Remote Branch come in Local Remote tracking branch (4.2) 远程分支中的更改来自本地远程跟踪分支(4.2)
    2. As my local master branch (4.1) is set to track Remote tracking brnach (4.2),they come in my local master branch (4.1). 由于我的本地主分支(4.1)设置为跟踪远程跟踪brnach(4.2),因此它们进入了我的本地主分支(4.1)。
    3. And from my master branch they come in working directory right? 从我的master分支进入工作目录吧?
  7. and the same happens in reverse when i try to push the changes Correct? 当我尝试推动更改时也会发生相反的情况对吗?
  1. True 真正
  2. False. 假。 Remote Tracking Branches are just local branches. 远程跟踪分支机构只是本地分支机构。 They definitely do not adjust themselves when you fetch from the remote repo. 当您从远程存储库中获取数据时,它们绝对不会自行调整。 Ever. 曾经
  3. True 真正
  4. True 真正
  5. No. There is no such thing as a local master and a separate remote tracking local master. 不会。没有本地主机和单独的远程跟踪本地主机之类的东西。 There can be only one local master. 只能有一个本地主机。
  6. Does not make any sense 没有任何意义
  7. Does not make any sense 没有任何意义

The remote-tracking-ness of a local branch affects only the pull and push operations. 本地分支的远程跟踪能力仅影响pullpush操作。 But not fetch . 但是不能fetch It allows you to omit a few arguments when you type these commands. 当您键入这些命令时,它允许您省略一些参数。

For instance the local master is remote-tracking origin/master. 例如,本地主机是远程跟踪源/主机。 To pull in the new commits from origin/master into the local master, you have to make sure your local master is checked out and then: 要将新提交从原始/母版拉入本地母版,必须确保已检出本地母版,然后:

git pull origin master

But as master is remote-tracking origin/master, it's enough to say: 但是,由于master是远程跟踪的原点/ master,因此可以这样说:

git pull

So remote-tracking is mostly syntactic sugar. 因此,远程跟踪主要是语法糖。

(For future readers) (供将来的读者使用)

I agree with the assumptions of the author of the question from 1 to 4. However (5) master can not track origin/master when fetch. 我同意问题作者从1到4的假设。但是(5)主机在获取时无法跟踪来源/主机。

When fetch (6), only origin/master is updated, so it is tracking the remote branch (6.1. is true). 提取(6)时,仅更新了原始服务器/主服务器,因此它正在跟踪远程分支(6.1。是)。

However, for the local master and the working dire you have to merge or rebase (even better the second one) (6.2 and 6.3. are false). 但是,对于本地管理员和工作困境,您必须合并或调整基准(甚至更好的是第二个基准)(6.2和6.3。是错误的)。

Same way, for push, you push your master in origin (name of remote repository). 同样,对于推送,您将主服务器推送到源服务器(远程存储库的名称)中。 Your local repo is when the changes of your working dir have been commited, so your working dir is not automatically pushed, is your local repo. 本地存储库是提交工作目录更改后的工作目录,因此不会自动推送您的工作目录,这是您的本地存储库。

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

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