How do I check out a remote Git branch?

后端 未结 30 1983
灰色年华
灰色年华 2020-11-22 00:12

Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.

<
30条回答
  •  既然无缘
    2020-11-22 00:29

    If the remote branch name begins with special characteres you need to use single quotes around it in the checkout command, or else git won't know which branch you are talking about.

    For example, I tried to checkout a remote branch named as #9773 but the command didn't work properly, as shown in the picture below:

    For some reason I wondered if the sharp symbol (#) could have something to do with it, and then I tried surrounding the branch name with single quotes, like '#9773' rathen than just #9773, and fortunately it worked fine.

    $ git checkout -b '#9773' origin/'#9773'
    

提交回复
热议问题