How to Create and Delete Git Tags in GitHub Repository

git tag is used to tag or mark a specific revision as significant, often this will be used during the build deployment and realsing of the code.  Once a tag is created, it’s often referred to by build and deploy scripts instead of the tag’s represented commit.  We can now easily create and delete git tags in GitHub.

Synopsis to Create and Delete Git Tags

git tag [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>]
	<tagname> [<commit> | <object>]
git tag -d <tagname>…​
git tag [-n[<num>]] -l [--contains <commit>] [--points-at <object>]
	[--column[=<options>] | --no-column] [--create-reflog] [--sort=<key>]
	[--format=<format>] [--[no-]merged [<commit>]] [<pattern>…​]
git tag -v <tagname>…​

To get the complete information on all the options with git tag command checkout Git Tag Official Documentation.

Tagging a Revision

If you would like to tag a specific revision in git, simply use the format git tag {tagname}

git tag 0.1.0

This will create a local tag with the current stat of the branch you are on. When you push the code to remote repository tags will not be included by default. You need to explictly pus the tags to your remote repo.

Push Tags to Remote Repository in GitHub

As we  saw earlier the tags are not pushed when you push your changes to remote repo. We need to manually push the tags to remote repo and below is the command to perfrom this action.

git push origin --tags

// All the tag references will be pushed to remote repository. 
//To Push Single Tag into remote repo use the below command

git push origin <tagname>
git push origin 0.0.1

Deleting a Git Tag from GitHub

Anytime if you need to remove the tag from the history or GitHub repository you can easily perfrom by using -d flag.

git tag -d 0.5.0
git push origin :refs/tags/0.5.0
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like