How to create a new branch from a tag?
Solution 1
Wow, that was easier than I thought:
git checkout -b newbranch v1.0
Solution 2
If you simply want to create a new branch without immediately changing to it, you could do the following:
git branch newbranch v1.0
Solution 3
I used the following steps to create a new hot fix branch from a Tag.
Syntax
git checkout -b <New Branch Name> <TAG Name>
Steps to do it.
git checkout -b NewBranchName v1.0
- Make changes to pom / release versions
- Stage changes
git commit -m "Update pom versions for Hotfix branch"
- Finally push your newly created branch to remote repository.
git push -u origin NewBranchName
I hope this would help.
Solution 4
I have resolve the problem as below 1. Get the tag from your branch 2. Write below command
Example: git branch <Hotfix branch> <TAG>
git branch hotfix_4.4.3 v4.4.3
git checkout hotfix_4.4.3
or you can do with other command
git checkout -b <Hotfix branch> <TAG>
-b stands for creating new branch to local
once you ready with your hotfix branch, It's time to move that branch to github, you can do so by writing below command
git push --set-upstream origin hotfix_4.4.3
Solution 5
The situation becomes a little bit problematic if we want to create a branch from a tag with the same name.
In this, and in similar scenarios, the important thing is to know: branches and tags are actually single-line text files in .git/refs
directory, and we can reference them explicitly using their pathes below .git
. Branches are called here "heads", to make our life more simple.
Thus, refs/heads/master
is the real, explicit name of the master
branch. And refs/tags/cica
is the exact name of the tag named cica
.
The correct command to create a branch named cica
from the tag named cica
is:
git branch cica refs/tags/cica
Mike
Updated on July 21, 2022Comments
-
Mike almost 2 years
I'd like to create a new master branch from an existing tag. Say I have a tag
v1.0
. How to create a new branch from this tag?-
Greg Bacon almost 12 yearspossible duplicate of Checkout GIT tag
-
-
wadesworld almost 12 yearsCorrect. Note you also could have just set the master branch back to the point of the tag with
git reset --hard v1.0
-
SalmonKiller over 5 yearsIf this doesn't work because of "<tag> is not a valid commit" or a similar error (often when working on a shared repository), refer to stackoverflow.com/questions/35979642/…
-
Nathan Long over 5 yearsThe suggestion from @wadesworld could work, but if anyone reads this and isn't 100% sure what it means to reset the master branch, don't do that.
-
peterh over 5 yearsPlease don't use screenshots if also text copy-paste would be enough.
-
javi_swift about 5 yearsI think this should be the accepted answer as it does exactly what is required. The accepted answer does something else not stated in the question.
-
Reaz Murshed about 4 yearsThis is a better answer that I found here - stackoverflow.com/a/35979751/3145960
-
Juljan about 2 yearsIf you last release was
v4.4.3
, shouldn't your new branch be called hotfix_4.4.4