Skip to content

Instantly share code, notes, and snippets.

@Lukas238
Last active September 17, 2020 20:34
Show Gist options
  • Save Lukas238/fb2821c718d65008e16d55512ba2af93 to your computer and use it in GitHub Desktop.
Save Lukas238/fb2821c718d65008e16d55512ba2af93 to your computer and use it in GitHub Desktop.
Batch group git tags by year

This script will:

  1. Search for git tag with names starting with a the year 2018 followd by a hypen character (grep ^2018-).

Make sure to change the year in the script with the year you want to match.

  1. Then it will create a new tag using the year 2018/´followed by the origina tag name. Ex.: 2018/2018-01-20 Release 2.
  2. The it will delete the original tag.
git tag -l |grep ^2018- | while read t; do git tag "2018/"$t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done

If you just want to bulk delete all tags starting on 2018- on Origin, you can use this command:

git tag -l |grep ^2018- | while read t; do git tag -d $t; git push origin :refs/tags/$t ; done

The rest of the team can then clean their local lists of tags, and then pull all online origin tags anew.

  1. Clean local tags: git tag -d $(git tag).
  2. Pull origin tags anew: git pull --tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment