git push --tags
is a separate operation to git push
since pushing tags should be a conscious choice to avoid accidentally pushing the wrong one. That's fine. But how do I push them both simultaneously / atomically? (git push && git push --tags
is not perfectly atomic.)
Update August 2020
As mentioned originally in this answer by SoBeRich, and in my own answer, as of git 2.4.x
git push --atomic origin <branch name> <tag>
(Note: this actually work with HTTPS only with Git 2.24)
Update May 2015
As of git 2.4.1, you can do
git config --global push.followTags true
If set to true enable --follow-tags option by default.
You may override this configuration at time of push by specifying --no-follow-tags.
As noted in this thread by Matt Rogers answering Wes Hurd:
--follow-tags
only pushes annotated tags.
git tag -a -m "I'm an annotation" <tagname>
That would be pushed (as opposed to git tag <tagname>
, a lightweight tag, which would not be pushed, as I mentioned here)
Update April 2013
Since git 1.8.3 (April 22d, 2013), you no longer have to do 2 commands to push branches, and then to push tags:
The new "
--follow-tags
" option tells "git push
" to push relevant annotated tags when pushing branches out.
You can now try, when pushing new commits:
git push --follow-tags
That won't push all the local tags though, only the one referenced by commits which are pushed with the git push
.
Git 2.4.1+ (Q2 2015) will introduce the option push.followTags
: see "How to make “git push
” include tags within a branch?".
Original answer, September 2010
The nuclear option would be git push --mirror
, which will push all refs under refs/
.
You can also push just one tag with your current branch commit:
git push origin : v1.0.0
You can combine the --tags
option with a refspec like:
git push origin --tags :
(since --tags
means: All refs under refs/tags
are pushed, in addition to refspecs explicitly listed on the command line)
You also have this entry "Pushing branches and tags with a single "git push" invocation"
A handy tip was just posted to the Git mailing list by Zoltán Füzesi:
I use
.git/config
to solve this:
[remote "origin"]
url = ...
fetch = +refs/heads/*:refs/remotes/origin/*
push = +refs/heads/*
push = +refs/tags/*
With these lines added
git push origin
will upload all your branches and tags. If you want to upload only some of them, you can enumerate them.Haven't tried it myself yet, but it looks like it might be useful until some other way of pushing branches and tags at the same time is added to git push.
On the other hand, I don't mind typing:$ git push && git push --tags
Beware, as commented by Aseem Kishore
push = +refs/heads/*
will force-pushes all your branches.
This bit me just now, so FYI.
René Scheibe adds this interesting comment:
The
--follow-tags
parameter is misleading as only tags under.git/refs/tags
are considered.
Ifgit gc
is run, tags are moved from.git/refs/tags
to.git/packed-refs
. Afterwardsgit push --follow-tags ...
does not work as expected anymore.
git push --tags :
doesn't work for me, but git push origin --tags :
did. Not sure if that's a configuration thing on my end or a typo on yours. –
Regorge push = +refs/heads/*
line force-pushes all your branches. This bit me just now, so FYI. –
Hacienda --follow-tags
flag added in git 1.8.3, can I configure my git installation to make that the default? –
Anchoveta push.default
(git-scm.com/docs/git-config) can define default actions on push (nothing
, matching
, upstream
, simple
as in https://mcmap.net/q/13083/-difference-between-git-checkout-track-origin-branch-and-git-checkout-b-branch-origin-branch). You need to add --follow-tag
explicitly. –
Waterbuck git push --follow-tags -f
didn't work for me. –
Nonprofit git push --follow-tags
–
Waterbuck push.default=simple
in your git config, then git push --follow-tags
doesn't work. In that case you still have to use git push && git push --tags
. –
Foster push.default
to simple
, and to a push --follow-tags
. The tags on the (single) branch you are pushing should be take into account. –
Waterbuck push.default
to matching
he could use git push --follow-tags
. Before that it didn't work. The git version of him is 1.8.5.2. –
Foster alias gpush='git push --follow-tags'
or alias gpush='git push && git push --tags'
would allow you just run gpush
at the command line to trigger whatever flavor push you want. –
Sandie --follow-tags
doesn't work with git 2.1.0. I have push.default=simple
, which is the default. –
Zoophilia git push --follow-tags
. Commit is pushed, tag is not. –
Zoophilia git pull
? –
Ivaivah git config --global push.followTags true
, you can make it the default for your repos. –
Waterbuck --follow-tags
parameter is misleading as only tags under .git/refs/tags
are considered. If git gc
is run, tags are moved from .git/refs/tags
to .git/packed-refs
. Afterwards git push --follow-tags ...
does not work as expected anymore. –
Eurhythmic git-config
, is that intentional? –
Wigwag git push
will stop pushing tags related to commits if git gc
has been run? Doesn't that mean --follow-tags
is partially broken, if it sometimes doesn't do its job based upon the history of the repository? (It's like git commit
will make a commit, but not if you used to have a branch named foo
and then deleted it.) Isn't that bug-filing-worthy? Or am misinterpreting the comment? –
Turf Since Git 2.4:
git push --atomic origin <branch name> <tag>
git push; git push --tags
–
Kynan Let's say you have created a new repo on github. So the first step would be to clone the repo:git clone {Your Repo URL}
You do your work, add some files, code etc., then push your changes with:
git add .
git commit -m "first commit"
git push
Now our changes are in main branch. Let's create a tag:
git tag v1.0.0 # creates tag locally
git push origin v1.0.0 # pushes tag to remote
If you want to delete the tag:
git tag --delete v1.0.0 # deletes tag locally
git push --delete origin v1.0.0 # deletes remote tag
git status
after your three commands and you will see something like "your branch is ahead of 'origin/develop' by 1 commit. (use "git push" to publish your local commits)" –
Adai git push origin 0.1.0
- you should omit the word 'tag'. Then it works really good. And for me even better than the --follow-tags option. –
Adai Just tested on git 2.31.0: git push <refspec> --tags
. This has the advantage that it pushes ALL tags, not just annotated tags like --follow-tags
.
To avoid triggering two CI builds for the same commit on Gitlab:
git push -o ci.skip && git push --tags
As suggested by @user1160006 here.
Git GUI has a PUSH button - pardon the pun, and the dialog box it opens has a checkbox for tags.
I pushed a branch from the command line, without tags, and then tried again pushing the branch using the --follow-tags
option descibed above. The option is described as following annotated tags. My tags were simple tags.
I'd fixed something, tagged the commit with the fix in, (so colleagues can cherry pick the fix,) then changed the software version number and tagged the release I created (so colleagues can clone that release).
Git returned saying everything was up-to-date. It did not send the tags! Perhaps because the tags weren't annotated. Perhaps because there was nothing new on the branch.
When I did a similar push with Git GUI, the tags were sent.
For the time being, I am going to be pushing my changes to my remotes with Git GUI and not with the command line and --follow-tags
.
© 2022 - 2024 — McMap. All rights reserved.
git push && git push --tags
? – Mabuse--follow-tags
option since git 1.8.3 – Waterbuck--tags
does not distinguish between lightweight and annotated tags source – Rossiyagit push && git push --tags
will trigger the CI pipeline twice, although this may have been irrelevant 10 years ago. – Glissadegit push -o ci.skip && git push --tags
– Nettles