"git push" and "git push --tags" in the same command?
Solution 1
The closest option may be:
git push --follow-tags
Push all the refs that would be pushed without this option, and also push annotated tags in refs/tags that are missing from the remote but are pointing at committish that are reachable from the refs being pushed.
Solution 2
According to the documentation of --tags
you can specify additional refspecs to be pushed.
So you can simply use
git push --tags origin HEAD
Solution 3
You can create alias to have a fast access to this command:
git config --global alias.p '!git push && git push --tags'
or
git config --global alias.pa '!git push --all && git push --tags'
now you can do it like this:
git tag v4.7
git p
You can read more about aliases here
![Nicolas Raoul](https://i.stack.imgur.com/F5gLZ.png?s=256&g=1)
Nicolas Raoul
I am Nicolas Raoul, IT consultant in Tokyo. Feel free to copy/paste the source code from my StackExchange answers, I release it to the public domain.
Updated on February 17, 2020Comments
-
Nicolas Raoul over 4 years
I usually run:
git push git tag v4.7 git push --tags
Both the first and third operations connect to the server, which wastes time.
I want to make it faster by pushing only once. What command(s) would achieve this?
It is in a bash script, and needs to run fine in any branch, not justmaster
.Reading the manual, I don't think
git push all
is the solution:--all: Instead of naming each ref to push, specifies that all refs under refs/heads/ be pushed.
--tags: All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.
-
Nicolas Raoul over 10 yearsThat sounds like a valid solution as well... How is it different from
git push --tags HEAD
? -
Kornel over 10 years@NicolasRaoul Like
git push
it also pushes other tracking branches (depends onpush.default
configuration), not justHEAD
, and it pushes tags on pushed branches, not all tags. -
Daniel Hilgarth over 10 yearsI don't think that is correct. AFAIK
git push
only pushes the current branch. -
torek over 10 yearsNote that
--follow-tags
will only push annotated tags (though often this is what you want anyway). -
kostix over 10 years@DanielHilgarth,
git push
without explicit refspecs passed to it behaves according to thepush.default
configuration variable, which, if absent, currently defaults tomatching
. -
Marius Gedminas over 9 yearsThis does not appear to work: "fatal: 'HEAD' does not appear to be a git repository".
git push origin HEAD --tags
works, though. -
Daniel Hilgarth over 9 years@MariusGedminas: Thanks for catching that. Fixed.
-
Nicolas Raoul over 7 yearsInteresting tip, but that does not reduce the number of requests made to the server, right? As explained in the question it is for a bash script, so my question is not about typing less.
-
Jacob Wang almost 7 yearsAs of git 2.0, the default if
push.default
is not set is set tosimple
which pretty much means the current branch. See this question