Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-branch

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.

like image 855
Sergi Avatar asked Sep 27 '11 16:09

Sergi


People also ask

Does git checkout pull from remote?

Git Checkout a Remote Branch Each remote repository will contain its own set of branches. In order to checkout a remote branch you have to first fetch the contents of the branch. In modern versions of Git, you can then checkout the remote branch like a local branch.

How do I checkout someone else's remote branch?

If you want to check out a remote branch someone published, you first have to use git fetch . This command downloads the references from your remote repository to your local machine, including the reference to the remote branch. Now all you need to do is use git checkout <remote branch name> .


1 Answers

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

like image 85
Joost Diepenmaat Avatar answered Sep 20 '22 13:09

Joost Diepenmaat