1587

I have a GitHub repository and I need to tag it.

I created a tag in a shell using the following command:

git tag 2.0
git tag
>>> 2.0

The tag does exist locally, but does not appear on GitHub.

How do I push this tag to GitHub?

0

10 Answers 10

2533

You can create tags for GitHub by either using:

  • the Git command line, or
  • GitHub's web interface.

Creating tags from the command line

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.

Creating tags through GitHub's web interface

You can find GitHub's instructions for this at their Creating Releases help page. Here is a summary:

  1. Click the releases link on our repository page,

    Screenshot 1

  2. Click on Create a new release or Draft a new release,

    Screenshot 2

  3. Fill out the form fields, then click Publish release at the bottom,

    Screenshot 3 Screenshot 4

  4. 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

  1. Click on edit button for the release

  2. Provide name of the new tag ABC_DEF_V_5_3_T_2 and hit tab

  3. 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

  4. Select branch or commit

  5. Check "This is a pre-release" checkbox for qa tag and uncheck it if the tag is created for Prod tag.

  6. After that click on "Update Release"

  7. This will create a new Tag within the existing Release.

9
  • 13
    @RandomDSdevel in github, release is just a tag. You can create tag from command line and push it to github remote. tag will appear as a release on githubs webpage.
    – Iuri G.
    Commented Feb 16, 2017 at 23:23
  • 9
    @IuriG.: Well, yes, but shouldn't you be able to create tags that don't automatically get picked up by GitHub as releases…? (Back when I originally created the comment to which you responded and to whose response of yours this one is a reply, tags at least used to get turned into releases automatically, though I don't know if this is still the case or not&thinsp;going by the workflow explained in your answer hints at this no longer being true. I submitted a support request to GitHub about this a while ago, but they had a bit of a support backlog back then, so my request was closed.) Commented Feb 20, 2017 at 2:38
  • 4
    via Github interface you can create only Light-weight tags. Commented Dec 5, 2018 at 19:42
  • 3
    Unfortunately, the github interface doesn't allow you to tag a commit unless it was in the last 24 hours or the last 10 (? or so?) commits.
    – tsalaroth
    Commented Jan 8, 2019 at 17:15
  • 5
    I don't think this works any more. I don't see "Draft a new release" button any more. Commented Jun 9, 2021 at 8:07
207

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
4
  • 2
    Do you add the tag BEFORE or after the git commit?
    – garfbradaz
    Commented Nov 4, 2018 at 18:28
  • 1
    I have added tag after git commit. Commented Nov 6, 2018 at 5:15
  • 8
    @garfbradaz When you make a tag it points to the latest commit, so after.
    – user4945014
    Commented Jul 17, 2020 at 23:57
  • And how do you git pull a tag?
    – Steve3p0
    Commented Jul 12, 2023 at 9:18
92

You just have to push the tag after you run the git tag 2.0 command.

So just do git push --tags now.

6
  • 68
    I'd rather suggest to use git push v2.0 instead of --tags, there might be other tags that should not be pushed.
    – tschoppi
    Commented May 15, 2017 at 13:26
  • 1
    That's only a problem if your local tags differ from your remote tags. They are easy to sync if that ever becomes a problem.
    – kjdion84
    Commented Sep 14, 2017 at 10:48
  • 3
    @kjdion84 No, that's also a problem if there are obsolete tags: All tags get always fetched and when someone uses --tags, it's hard to get rid of them.
    – maaartinus
    Commented Oct 12, 2017 at 16:05
  • 4
    or git push origin v2.0 Commented Nov 15, 2017 at 1:33
  • 2
    @tschoppi you can use git push --follow-tags to ensure to only push tags related to commits you're actually pushing
    – Vitim.us
    Commented Jan 10, 2020 at 18:13
92

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.

0
20

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:

  • the person who made the tag
  • the date the tag was made
  • a message for the tag

Because of this, you should always use annotated tags.

8

It all depends what type of tag you want to create:

  • If you want to create Annotated tags, to show extra metadata, you can do it in the following way: git tag -a v1.0.0.
  • On the other hand, Lightweight tags are used to "bookmark" your commits for private use: git tag v1.0.0.

There are a few other tag functionalities such as:

  • Listing tags - git tag -l -n3. The command lists all existing tags with maximum 3 lines of their tag message. By default -n only shows the first line.
  • Tag details - git show <tag_identifier>. It shows all you need to know about a specific tag.
  • Sorting tags - git tag --sort=<type>
  • Publishing tags - git push origin v1.0. You can git push the tag individually, or you can run git push --tags which will push all tags at once.

Be sure to check this tag related article for more relevant information.

7

Using Sourcetree

Here are the simple steps to create a GitHub Tag, when you release build from master.

  1. Open source_tree tab

    step 1

  2. Right click on Tag sections from Tag which appear on left navigation section

    step 2

  3. Click on New Tag()

  4. A dialog appears to Add Tag and Remove Tag
  5. Click on Add Tag from give name to tag (preferred version name of the code)

    step 3

  6. If you want to push the TAG on remote, while creating the TAG ref: step 5 which gives checkbox push TAG to origin check it and pushed tag appears on remote repository

  7. In case while creating the TAG if you have forgotten to check the box Push to origin, you can do it later by right-clicking on the created TAG, click on Push to origin. enter image description here

2
  • 2
    This answer explains how to create a local tag using Sourcetree, but the question is all about how to push the tag to the remote repository (GitHub in this case). You say to do this in step 6, but you left out the instructions for it. Commented Feb 17, 2019 at 19:11
  • @RoryO'Kane please check it now I have updated my answer, Thanks for pointing it out Commented Mar 17, 2019 at 13:29
2

To create a tag, you can simply run git tag <tagname> command by replacing <tagname> with the actual name of the tag. Here is a complete tutorial on the basics of managing git tags.

1

If you use Intellij, you can use the menu "Git/New Tag", then CTRL-SHIFT-K and check the "push tags" checkbox at the bottom of the dialog. This tag will appear in github, without creating a release.

push commit with tags with intellij

0

For SourceTree users:

Right click on a commit and select "Tag...", then just be sure to check the "push tag" box.

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.