"git push" and "git push --tags" in the same command?

23,747

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

Share:
23,747
Nicolas Raoul
Author by

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, 2020

Comments

  • Nicolas Raoul
    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 just master.

    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
    Nicolas Raoul over 10 years
    That sounds like a valid solution as well... How is it different from git push --tags HEAD?
  • Kornel
    Kornel over 10 years
    @NicolasRaoul Like git push it also pushes other tracking branches (depends on push.default configuration), not just HEAD, and it pushes tags on pushed branches, not all tags.
  • Daniel Hilgarth
    Daniel Hilgarth over 10 years
    I don't think that is correct. AFAIK git push only pushes the current branch.
  • torek
    torek over 10 years
    Note that --follow-tags will only push annotated tags (though often this is what you want anyway).
  • kostix
    kostix over 10 years
    @DanielHilgarth, git push without explicit refspecs passed to it behaves according to the push.default configuration variable, which, if absent, currently defaults to matching.
  • Marius Gedminas
    Marius Gedminas over 9 years
    This does not appear to work: "fatal: 'HEAD' does not appear to be a git repository". git push origin HEAD --tags works, though.
  • Daniel Hilgarth
    Daniel Hilgarth over 9 years
    @MariusGedminas: Thanks for catching that. Fixed.
  • Nicolas Raoul
    Nicolas Raoul over 7 years
    Interesting 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
    Jacob Wang almost 7 years
    As of git 2.0, the default if push.default is not set is set to simple which pretty much means the current branch. See this question