git: switch branch without detaching head

后端 未结 4 1661
野趣味
野趣味 2020-11-28 18:38

I have a repository on github with a main branch (master) and a branch for some experimental work. I made some commits and pushed to the experimental branch and everything

4条回答
  •  眼角桃花
    2020-11-28 19:19

    To expand on Kent's reply, after you do your clone the only branch you'll have (remotes don't count) is the one that was active in the repository you cloned from -- master in your case.

    So, first you'll want to create a new branch to track the remote experimental branch:

    $ git branch experimental origin/experimental
    

    and then check it out:

    $ git checkout experimental
    

    However, Kent is correct -- these two commands can be combined

    $ git checkout -b experimental origin/experimental
    

提交回复
热议问题