Reputation: 4805
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 original
s 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?
Upvotes: 9
Views: 35469
Reputation: 1634
The following bash script can be used for automating this process:
#!/bin/bash
old_name="old-branch-name"
new_name="new-branch-name"
git checkout ${old_name}
git branch -m ${old_name} ${new_name}
git push origin :${old_name} ${new_name}
git push origin -u ${new_name}
echo "Branch ${old_name} renamed to ${new_name}"
Upvotes: -2
Reputation: 169
This worked for me
$git fetch --tags
$git tag
$git checkout -b <new_branch_name> <tagname>
Upvotes: 15
Reputation: 70673
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
Upvotes: 6
Reputation: 3996
You need to wrap this in two instructions
git checkout tagname && git checkout -b newbranch
Alternatively
git checkout tagname -b newbranch
Upvotes: 25