How git clone actually works

后端 未结 5 1306
暗喜
暗喜 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:31

    To put it simply, git clone repository-url does the following things, in order:

    1. Creates a new empty repository.

      git init
      
    2. Creates a remote called "origin" and sets it to the given url.

      git remote add origin repository-url
      
    3. Fetches all commits and remote branches from the remote called "origin".

      git fetch --all
      
    4. Creates a local branch "master" to track the remote branch "origin/master".

      git checkout --track origin/master
      

    An interesting point is that a fork (in GitHub or Bitbucket) is just a server side clone.

提交回复
热议问题