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

后端 未结 7 1730
礼貌的吻别
礼貌的吻别 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条回答
  •  旧时难觅i
    2020-11-29 16:47

    git checkout -b BRANCH_NAME creates a new branch and checks out the new branch while git branch BRANCH_NAME creates a new branch but leaves you on the same branch.

    In other words git checkout -b BRANCH_NAME does the following for you.

    git branch BRANCH_NAME    # create a new branch
    git switch BRANCH_NAME    # then switch to the new branch
    

提交回复
热议问题