Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git branch from remote tag

I've created a new local git repository mirrored from another remote repository:

git init
git remote add original {url}
git pull original master
git remote add origin {url}
git push -u origin master

This would create a mirror of originals master branch. Now I would like to create a new branch of a tag from original.

How the commands should look like? I tried git checkout -b newbranch original/tagname but I got:

fatal: Cannot update paths and switch to branch 'newbranch' at the same time.
Did you intend to checkout 'original/tagname' which can not be resolved as commit?
like image 924
dtrunk Avatar asked Feb 23 '13 17:02

dtrunk


People also ask

Can you branch from a tag git?

The best way to work with git tags is to create a new branch from the existing tag. It can be done using git checkout command.

How do you get specific branch from remote?

If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.

How do I checkout a remote tag?

In order to checkout a Git tag, use the “git checkout” command and specify the tagname as well as the branch to be checked out. Note that you will have to make sure that you have the latest tag list from your remote repository.


3 Answers

You need to wrap this in two instructions

git checkout tagname && git checkout -b newbranch

Alternatively

git checkout tagname -b newbranch
like image 86
jchapa Avatar answered Oct 25 '22 17:10

jchapa


This worked for me

$git fetch --tags
$git tag
$git checkout -b <new_branch_name> <tagname>
like image 38
nicky12345 Avatar answered Oct 25 '22 16:10

nicky12345


There is no concept of “remote tracking tags” like there are “remote tracking branches”. You either get the tags from the repo or you don’t. At least in the standard settings. You can change that, but I would not recommend that. Does this not work?

git checkout -b newbranch tagname
like image 42
Chronial Avatar answered Oct 25 '22 16:10

Chronial