In order to create a new tag, you have to use the “git tag” command and specify the tag name that you want to create. As an example, let's say that you want to create a new tag on the latest commit of your master branch. To achieve that, execute the “git tag” command and specify the tagname.
GitHub Desktop allows you to create annotated tags. Tags are associated with commits, so you can use a tag to mark an individual point in your repository's history, including a version number for a release.
Technically you can tag the content of a single file without it's file name. But such tags are of limited use. Tags are expected to point to commits, and special tags to non-commits have very different behavior (you can't git checkout such a special tag). So I strongly suggest to never use non-commit tags.
You can create tags for GitHub by either using:
To create a tag on your current branch, run this:
git tag <tagname>
If you want to include a description with your tag, add -a
to create an annotated tag:
git tag <tagname> -a
This will create a local
tag with the current state of the branch you are on. When pushing to your remote repo, tags are NOT included by default. You will need to explicitly say that you want to push your tags to your remote repo:
git push origin --tags
From the official Linux Kernel Git documentation for git push
:
--tags
All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.
Or if you just want to push a single tag:
git push origin <tag>
See also my answer to How do you push a tag to a remote repository using Git? for more details about that syntax above.
You can find GitHub's instructions for this at their Creating Releases help page. Here is a summary:
Click the releases link on our repository page,
Click on Create a new release or Draft a new release,
Fill out the form fields, then click Publish release at the bottom,
After you create your tag on GitHub, you might want to fetch it into your local repository too:
git fetch
Now next time, you may want to create one more tag within the same release from website. For that follow these steps:
Go to release tab
Click on edit button for the release
Provide name of the new tag ABC_DEF_V_5_3_T_2 and hit tab
After hitting tab, UI will show this message: Excellent! This tag will be created from the target when you publish this release. Also UI will provide an option to select the branch/commit
Select branch or commit
Check "This is a pre-release" checkbox for qa tag and uncheck it if the tag is created for Prod tag.
After that click on "Update Release"
This will create a new Tag within the existing Release.
Creating Tags
Git uses two main types of tags: lightweight and annotated.
Annotated Tags:
To create an annotated tag in Git you can just run the following simple commands on your terminal.
$ git tag -a v2.1.0 -m "xyz feature is released in this tag."
$ git tag
v1.0.0
v2.0.0
v2.1.0
The -m denotes message for that particular tag. We can write summary of features which is going to tag here.
Lightweight Tags:
The other way to tag commits is lightweight tag. We can do it in the following way:
$ git tag v2.1.0
$ git tag
v1.0.0
v2.0.0
v2.1.0
Push Tag
To push particular tag you can use below command:
git push origin v1.0.3
Or if you want to push all tags then use the below command:
git push --tags
List all tags:
To list all tags, use the following command.
git tag
You just have to push the tag after you run the git tag 2.0
command.
So just do git push --tags
now.
In case you want to tag a specific commit like i do
Here's a command to do that :-
Example:
git tag -a v1.0 7cceb02 -m "Your message here"
Where 7cceb02
is the beginning part of the commit id.
You can then push the tag using git push origin v1.0
.
You can do git log
to show all the commit id's in your current branch.
CAREFUL: In the command in Lawakush Kurmi's answer (git tag -a v1.0
) the -a
flag is used. This flag tells Git to create an annotated flag. If you don't provide the flag (i.e. git tag v1.0
) then it'll create what's called a lightweight tag.
Annotated tags are recommended, because they include a lot of extra information such as:
Because of this, you should always use annotated tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With