How git clone actually works

后端 未结 5 1309
暗喜
暗喜 2021-01-31 06:04

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

When I clone the repository and run $ git branch it shows only

5条回答
  •  醉梦人生
    2021-01-31 06:07

    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
    

    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.

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

提交回复
热议问题