Git offers a feature called tagging which allows you to mark spots on your repository with version numbers so you can go back to specific versions easily.

Add a Tag

git tag -a <TAG_NAME> <COMMIT_HASH> -m "<YOUR MESSAGE>" 

For example…

git tag -a v1.0.0 3e42114 -m "Initial Version" 

The hash can also be left off and it will use the latest one.

View All Tags

git tag

Delete a Tag

git tag -d <TAG_NAME>

Push Tag to Remote Repo

git push --tags

Checkout a Tag

When you are ready to publish your new tag or need to rollback to an older one, just run this…

git checkout tags/<TAG_NAME>

Rename a Tag

You will do this in four steps… 1) create new tag from the old one; 2) delete old tag; 3) remove old tags from remote repo; 4) push new tag to remote repo

git tag <NEW_TAG_NAME> <OLD_TAG_NAME>
git tag -d <OLD_TAG_NAME>
git push origin :refs/tags/<OLD_TAG_NAME>
git push --tags

Purge Local Tags that Don’t Exist on Remote Server

If you have had to rename/remove tags, any other server that already fetched those old tags will still have them locally.  On each server you can run the commands below to purge all local tags and then re-fetch the remote tags.

git tag -l | xargs git tag -d
git fetch

Thanks goes to Richard W for this nice solution.

0 0 votes
Article Rating
in Git
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments