Skip to content

Instantly share code, notes, and snippets.

@nsmith-
Last active November 20, 2018 23:17
Show Gist options
  • Save nsmith-/6d9d29ed66cf71e0e92e to your computer and use it in GitHub Desktop.
Save nsmith-/6d9d29ed66cf71e0e92e to your computer and use it in GitHub Desktop.
# Delete all tags
git ls-remote -t my-cmssw | sed 's:^.*refs/tags/::' | while read t; do git push my-cmssw :$t; done
# Delete all branches
git ls-remote -h my-cmssw |sed 's:^.*refs/heads/::' | while read b; do git push my-cmssw :$b; done
# Or, save list of branches, and remove ones you want to keep
git ls-remote -h my-cmssw |sed 's:^.*refs/heads/::' > branches_to_del
vim branches_to_del
while read b; do git push my-cmssw :$b; done < branches_to_del
@fwyzard
Copy link

fwyzard commented Apr 10, 2018

I haven't tested it, but I think

git ls-remote -t my-cmssw | sed 's|^.*refs/tags/|:|' | xargs git push my-cmssw

should be faster for people with many tags

@kpedro88
Copy link

Here is a similar command, but avoids an issue that occurred in practice when the list of tags was too long for GitHub to accept it all at once:

git ls-remote --tags my-cmssw | cut -f2 | sed 's~refs/tags/~~' | xargs -n 1000 -P 1 git push my-cmssw --delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment