Skip to content

Instantly share code, notes, and snippets.

@ThrowsException
Created April 14, 2022 23:46
Show Gist options
  • Save ThrowsException/dc62e7e0727c4e12ce0cacab557aff4d to your computer and use it in GitHub Desktop.
Save ThrowsException/dc62e7e0727c4e12ce0cacab557aff4d to your computer and use it in GitHub Desktop.
Find branches matching a pattern and tag them
IFS=$'\n'
for b in $(git for-each-ref --format='%(objectname) %(refname:lstrip=-1)' 'refs/remotes/origin/RELEASE-2021*' 'refs/remotes/origin/RELEASE-2020*' 'refs/remotes/origin/RELEASE-2019*' --count=1); do
sha=$(echo "$b" | cut -d' ' -f1)
branch=$(echo "$b" | cut -d' ' -f2)
echo "$sha"
echo "$branch"
git tag "$branch" "$sha"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment