What is the difference between “git branch” and “git checkout -b”?

后端 未结 7 1679
礼貌的吻别
礼貌的吻别 2020-11-29 16:18

I used git checkout -b to create a new branch. I think that git branch does the same thing. How do these two commands differ, if they differ at all

7条回答
  •  自闭症患者
    2020-11-29 16:46

    There are forms of both commands that are similar (looking at git-scm docs Version 2.11.1):

    git branch  
    

    and

    git checkout -b  
    

    The latter executing the branch command first and then adding the checkout. In that form explicitly references to git-branch's doc:

    Specifying -b causes a new branch to be created as if git-branch[2] were called and then checked out

提交回复
热议问题