Archiving old git branches

Recently one of my projects have grown out of hand with various branch changes. The following is a command to tag and delete branches matching a certain grep pattern. This helps make listing all branches “git branch -v” less cluttered (but end up cluttering the git tag list)


git branch -v|grep "1.0.0-bugfix-xxx" | cut -f3 -d' ' | xargs -I {} sh -c "git tag archive/{} {} && git branch -D {}"

have to run this while not in any of the above matching branches otherwise the branch delete will fail.