Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list unpushed Git tags

I'd like to see which tags I have locally that aren't available on a particular remote. How can I do this? I know I can do git push --tags to push all of them. However, if there are some tags that I don't want pushed, how to I make sure I haven't missed some?

like image 571
Ben Lings Avatar asked Jul 03 '12 09:07

Ben Lings


People also ask

How will you list your tags in git?

List Local Git Tags. In order to list Git tags, you have to use the “git tag” command with no arguments. You can also execute “git tag” with the “-n” option in order to have an extensive description of your tag list. Optionally, you can choose to specify a tag pattern with the “-l” option followed by the tag pattern.

How do I fetch all tags?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.

How do I remove a local tag?

Use Git to delete a Git tag To delete the Git tag from the local repo, run the git tag -d tag-name command where tag-name is the name of the Git tag you want to delete.


1 Answers

You can use the following to see the tags that exist locally but not in the specified remote:

git show-ref --tags | grep -v -F "$(git ls-remote --tags <remote name> | grep -v '\^{}' | cut -f 2)" 

Note that git ls-remote shows both the annotated tag and the commit it points to with ^{}, so we need to remove the duplicates.

An alternative is to use the --dry-run/-n flags to git push:

git push --tags --dry-run 

This will show what changes would have been pushed, but won't actually make these changes.

like image 150
Ben Lings Avatar answered Sep 21 '22 23:09

Ben Lings