3294

I added a tag to the master branch on my machine:

git tag mytag master

How do I push this to the remote repository? Running git push gives the message:

Everything up-to-date

However, the remote repository does not contain my tag.

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Jonas
  • 121,568
  • 97
  • 310
  • 388

13 Answers13

5399

To push a single tag:

git push origin <tag_name>

And the following command should push all tags (not recommended):

# not recommended
git push --tags
700 Software
  • 85,281
  • 83
  • 234
  • 341
Trevor
  • 55,264
  • 2
  • 18
  • 12
  • 633
    I recommend not using or training others to use `git push --tags` as it can be very very difficult to get rid of bad tags when your co-workers are trained to push all tags, as people continue to push the old bad tags they have locally every time they want to push a new tag. Because of this, I will only every advise someone to use `git push origin ` now. – Scott Jungwirth Sep 25 '14 at 23:47
  • 68
    To push a **moved** tag: `git push origin --force` – Bob Stein May 25 '15 at 18:45
  • 30
    If your tag is the same as remote branch and `git push` fails with `error: src refspec matches more than one.`, you can push it as `git push origin tag ` – Volodymyr Sapsai Dec 10 '15 at 06:13
  • 7
    Note that `git push --tags origin ` **IS NOT** what you want - despite naming a specific tag, it pushes them all, even lightweight ones. Sigh. – nealmcb Nov 01 '17 at 00:58
  • 15
    If you want to push all tags, you could first `git push --dry-run --tags origin` to see what will get pushed. – axxis Jul 15 '19 at 15:46
  • `git push origin ` not worked for me. `git push origin refs/tags/`works. – user2027712 Sep 16 '22 at 02:34
1511

git push --follow-tags

This is a sane option introduced in Git 1.8.3:

git push --follow-tags

It pushes both commits and only tags that are both:

  • annotated
  • reachable (an ancestor) from the pushed commits

This is sane because:

It is for those reasons that --tags should be avoided.

Git 2.4 has added the push.followTags option to turn that flag on by default which you can set with:

git config --global push.followTags true

or by adding followTags = true to the [push] section of your ~/.gitconfig file.

Visual Studio Code

To activate this in Visual Studio Code set the variable "git.followTagsWhenSync": true on a user or workspace basis. GitHub

theking2
  • 2,174
  • 1
  • 27
  • 36
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • 1
    It was not clear at once for me that it was an and-relation between "annotated" and "reachable from the pushed commits". I hoped it would push all reachable tags, whatever if annotated or not. Maybe edit to make sure it's not an OR? – Gauthier Jun 11 '15 at 13:00
  • 34
    This doesn't work for me in git 2.5.0, but `git push origin --tags` does. – nnyby Jan 20 '16 at 19:35
  • @nnyby please provide a minimal example with all necessary commands from repo creation to failure and post it on a gist so I can try to reproduce ;-) – Ciro Santilli OurBigBook.com Jan 20 '16 at 19:44
  • 4
    Thanks for the push.followTags tip. I can't believe this isn't the out-of-the-box default. Without it, don't even bother to tag, you'll forget and get out of sync tags. – moodboom May 02 '16 at 22:38
  • Added a line about setting the follow-tags through the config file. – einpoklum Jun 26 '20 at 17:50
329

To push specific, one tag do following git push origin tag_name

solgar
  • 4,312
  • 2
  • 26
  • 30
127

To expand on Trevor's answer, you can push a single tag or all of your tags at once.

Push a Single Tag

git push <remote> <tag>

This is a summary of the relevant documentation that explains this (some command options omitted for brevity):

git push [[<repository> [<refspec>…]]

<refspec>...

The format of a <refspec> parameter is…the source ref <src>, followed by a colon :, followed by the destination ref <dst>

The <dst> tells which ref on the remote side is updated with this push…If :<dst> is omitted, the same ref as <src> will be updated…

tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.

Push All of Your Tags at Once

git push --tags <remote>
# Or
git push <remote> --tags

Here is a summary of the relevant documentation (some command options omitted for brevity):

git push [--all | --mirror | --tags] [<repository> [<refspec>…]]

--tags

All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.

Community
  • 1
  • 1
92

Add a tag in your current branch. If you want to create the tag for your master, first check out to master.

git tag tag_name

Check if it's created or not

git tag

Push in your remote origin

git push origin tag_name
Raisul Islam
  • 1,161
  • 1
  • 9
  • 18
89

You can push all local tags by simply git push --tags command.

$ git tag                         # see tag lists
$ git push origin <tag-name>      # push a single tag
$ git push --tags                 # push all local tags 
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
68

Tags are not sent to the remote repository by the git push command. We need to explicitly send these tags to the remote server by using the following command:

git push origin <tagname>

We can push all the tags at once by using the below command:

git push origin --tags

Here are some resources for complete details on git tagging:

http://www.cubearticle.com/articles/more/git/git-tag

http://wptheming.com/2011/04/add-remove-github-tags

Ashutosh Meher
  • 697
  • 5
  • 10
55

You can push the tags like this git push --tags

Fernando Diaz Garrido
  • 3,995
  • 19
  • 22
27

How can I push my tag to the remote repository so that all client computers can see it?

Run this to push mytag to your git origin (eg: GitHub or GitLab)

git push origin refs/tags/mytag

It's better to use the full "refspec" as shown above (literally refs/tags/mytag) just in-case mytag is actually v1.0.0 and is ambiguous (eg: because there's a branch also named v1.0.0).

Michael Altfield
  • 2,083
  • 23
  • 39
22

I am using git push <remote-name> tag <tag-name> to ensure that I am pushing a tag. I use it like: git push origin tag v1.0.1. This pattern is based upon the documentation (man git-push):

OPTIONS
   ...
   <refspec>...
       ...
       tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.
Carl G
  • 17,394
  • 14
  • 91
  • 115
8

push tag to remote

git push origin mytag

fetch all tags from remote

git fetch --all --tags
Ali80
  • 6,333
  • 2
  • 43
  • 33
3

I did something like this :

git push --tags origin <branch-name> <tag-name>

e.g. : git push --tags origin master v2.0
Alferd Nobel
  • 3,185
  • 2
  • 30
  • 35
2

In my case I am using Git version 2.30.0 I tried both --follow-tags and --tags, but both of them didn't work to push all the tags to the remote repo. I ended up using:

+refs/remotes/origin/tags/*:refs/tags/*

So for those who are looking for a way to push all the tags (along with master) to a remote repo, you can just add the following +refs/remotes/origin/tags/*:refs/tags/* to your push command.

So your command should be something like this:

git push path/to/your/repo +refs/remotes/origin/tags/*:refs/tags/*

It will successfully create all your tags in the remote repo.

cнŝdk
  • 31,391
  • 7
  • 56
  • 78
  • Why overcomplicate life mate – Mehdi Jun 21 '23 at 10:19
  • @Mehdi how is that? It's just the command I used in my case when we are unable to push tags to a remote, in my cas that was the unique way to do it. – cнŝdk Jun 21 '23 at 11:16
  • That was not the question though – Mehdi Jun 21 '23 at 19:46
  • Yes, maybe but it's worthy posting it, as I said **it's for for those who struggle to push *all their tags to a remote***. It might be helpful for someone else. – cнŝdk Jun 22 '23 at 11:00