What determines default branch after “git clone”?

前端 未结 4 619
既然无缘
既然无缘 2020-11-28 06:43

My understanding is that the default branch of a cloned repository is to be whatever HEAD points to in the repo being cloned.

I now have a case where this is not tru

4条回答
  •  [愿得一人]
    2020-11-28 07:28

    A bare repo has a HEAD, too. That's what you get when you clone it.

    From the git clone documentation:

    Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the cloned repository's currently active branch.

    The bit about "currently active branch" is referring to the remote's HEAD revision.

    If you want different behaviour, you can use --branch or -b:

    --branch
    -b
    Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.

提交回复
热议问题