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

烈酒焚心 提交于 2019-12-03 08:14:39

问题


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 origin is the remote and deploy is the tag I want to check out, but I get

fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/deploy' which can not be resolved as commit?

UPDATE: I've just discovered that

git fetch --all -t

was not working properly for me. While it downloads all branches, it does not download all tags, so when I checked out deploy it was and old tag. Now I execute

git fetch --all && git fetch -t

This way when I create a new branch based on a tag

git checkout -b test deploy

the new branch is up to date with the last deploy.


回答1:


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



回答2:


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".




回答3:


You need to run

git pull
git checkout -b <new-branch-name> remotes/origin/<source-branch-name>



回答4:


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>


来源:https://stackoverflow.com/questions/7572647/how-to-do-a-git-checkout-b-branchname-from-a-remote-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!