Why is “git branch” silent in new repositories?

后端 未结 3 1270
清酒与你
清酒与你 2021-01-14 23:44

When you create a new repository and run git branch, it exits silently. For example:

$ mkdir /tmp/foo; cd /tmp/foo; git init
Initialized empty G         


        
3条回答
  •  粉色の甜心
    2021-01-15 00:25

    Note that a branch is simply a pointer to a commit.
    Since an empty repo (with its empty tree) has no commit, you have no branch.

    A first commit will create a branch named 'master', because HEAD references refs/heads/master.
    Should you want to create a first commit on a different branch (than master), you would need to change the symbolic ref of HEAD first (as detailed in this thread):

    git symbolic-ref HEAD refs/heads/non-master 
    

    And then make your first commit.

提交回复
热议问题