git clone实际上如何工作 [英] How git clone actually works

查看:79
本文介绍了git clone实际上如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Github上有一个存储库,其中有2个分支:masterdevelop.

I have a repository on Github with 2 branches: master and develop.

当我克隆存储库并运行$ git branch时,它仅显示master分支.
如果运行$ git branch -a,我可以看到所有远程分支.

When I clone the repository and run $ git branch it shows only the master branch.
If I run $ git branch -a I can see all the remote branches.

现在,如果我执行$ git checkout develop,我会收到消息:

Now, if I do a $ git checkout develop, I get the message:

建立分支开发以跟踪从源头开始的远程分支开发.
切换到新的分支开发"

Branch develop set up to track remote branch develop from origin.
Switched to a new branch 'develop'

实际上发生了什么?当我运行$ git clone remote-url或运行$ git checkout develop时,是否获取了来自远程develop分支的提交?

What actually happened? Were the commits from the remote develop branch fetched when I ran $ git clone remote-url, or when I ran: $ git checkout develop, or neither?

签出develop后是否要做$ git pull origin develop,或者已经完成了?

Have I to do a $ git pull origin develop after checking out develop, or it's already done?

请帮助我了解远程上有多个分支时clone的工作原理.

Please help me understand how clone works when there are multiple branches on remote.

推荐答案

git clone获取所有远程分支,但仅为您创建一个本地分支master.因此,当您运行git branch -a时,您会看到类似以下内容的内容:

git clone fetches all remote branches, but only creates one local branch, master, for you. So when you run git branch -a, you'll see something like this:

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/develop
  remotes/origin/master

这意味着您有一个本地分支master和几个远程分支.当您运行git checkout develop时,git会创建另一个本地分支develop跟踪远程分支origin/develop. git尝试同步跟踪分支,因此您不必在check out之后再执行另一个pull.

which means that you have one local branch master and several remote branches. When you ran git checkout develop, git creates another local branch develop to track remote branch origin/develop. git tries to synchronize tracking branches, so you don't have to do another pull after check out.

如果您对本地和远程分支机构的术语感到困惑,则可以浏览此文档.它有一些不错的数据可以帮助您理解它们,以及在进行进一步的提交时本地和远程分支如何移动.

If the local and remote branches terminologies sound confusing to you, you can browse through this document. It has some nice figures to help you understand them, and how local and remote branches move when you do further commits.

您可能会发现此答案很有帮助:如何克隆所有是Git的远程分支吗?,第一个答案.

You may find this answer helpful: How to clone all remote branches in Git?, the first answer.

这篇关于git clone实际上如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆