1

I understand that you push a tag by running:

git push origin v0.1.0

Where v0.1.0 is the name of the tag I created. I am looking for a command that just pushes the last tag I created, without needing to specify the number/name of the tag.

rudy750
  • 23
  • 3
  • You can push all tags: `git push origin --tags`. This does what you want if the tag you just made is the only tag not on remote – alamoot Dec 19 '19 at 19:27
  • wouldn't that push all of the tags? I just want the latest – rudy750 Dec 19 '19 at 19:33
  • Assuming your local tags are the same as the remote, then pushing them causes no harm. But in general pushing all tags is not the best of ideas https://stackoverflow.com/a/5195913 – alamoot Dec 19 '19 at 19:35

1 Answers1

1

If you're creating a tag at the HEAD, you'll do something like:

git tag <tagName>

If you use bash, on the very next terminal command you can do:

git push origin !$

!$ referes to the last word of the last command, which in this case will be your <tagName>.

In general, you can get the list of sorted tags like this:

git tag --sort=creatordate

Using that, you can push your last tag like this:

git push origin $(git tag --sort=creatordate | tail -n 1)
alamoot
  • 1,966
  • 7
  • 30
  • 50