My blog, keeping you up-to-date with my latest news.

 

How to rename a tag in Git?

Linux • 2013-04-19

 

Today, I had the urge to change all my naming conventions tags for GotCms. The old version looked like v0.1.5 but the letter - v - was too much. Then I find a tiny but good solution to rename tags.

In first, you can't really do that. Git allow you to link old_tag with new_tag, but you must delete the old tag. This isn't a renaming but a replacement.

List my current tags :

$ git tag
v0.1
v0.1.1
v0.1.2
v0.1.3
v0.1.4
v0.1.5
v0.1a
v0.1b

Link my new tag 0.1.5 with the old v0.1.5

$ git tag 0.1.5 v0.1.5

List new tags

$ git tag
v0.1
v0.1.1
v0.1.2
v0.1.3
v0.1.4
v0.1.5
v0.1a
v0.1b
0.1.5

I did it for all my tags but old tags were still here.
Then I deleted old tags with this command.

$ git tag -d v0.1.5

And I got

$ git tag
0.1.0
0.1.0a
0.1.0b
0.1.1
0.1.2
0.1.3
0.1.4
0.1.5

But how to push tags modifications ? with - git push --tags - ?
And the answer is: No
Git push with --tags parameter will only adding new tag(s) without deleting the old tag(s), this is a precaution that git takes to avoid removing tags.
You must use this command for every tag you want to rename:

$ git push origin :refs/tags/v0.1.5

And it's done your old tag is removed from your server.

<< Back to Blog Discuss this post

 

Comments

 

No comments

 

Add a comment

 

Categories