How to do a “git checkout -b ” from a remote tag

前端 未结 4 545
不知归路
不知归路 2021-02-03 20:32

I\'m trying to create a branch from a remote tag, but it seems there\'s no way to do it. When I try

git checkout -b test origin/deploy

where or

相关标签:
4条回答
  • 2021-02-03 20:44

    to list all the tags

    git fetch
    git tags -l 
    

    to create a local branch that points to the tag

    git checkout tags/<tag_name> -b <branch_name>
    git checkout -b <branch_name> tags/<tag_name>
    
    0 讨论(0)
  • 2021-02-03 20:56

    I'm not sure you can do this directly. You're probably stuck with doing a fetch and then a checkout:

    git fetch origin
    git checkout -b test tag-name
    

    By the way, I wouldn't recommend using a tag name like "deploy".

    0 讨论(0)
  • 2021-02-03 21:03

    I'm not a git guru, but I had used something like this before and it seemed to have worked fine:

    git pull (or fetch, just need to make sure you are updated)
    git checkout -b test remotes/origin/deploy
    
    0 讨论(0)
  • 2021-02-03 21:04

    You need to run

    git pull
    git checkout -b <new-branch-name> remotes/origin/<source-branch-name>
    
    0 讨论(0)
提交回复
热议问题