Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cleans up local tracking branches that dont exist on the remote. Removes all remote branches that have been merged into master.
# clean up merged local branches
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
# clean up merged remote branches
git fetch -p && git branch -r --merged |
grep origin |
grep -v '>' |
grep -v 'rel_' |
grep -v 'emer_' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
@trashhalo

This comment has been minimized.

Copy link
Owner Author

trashhalo commented Feb 7, 2014

Change Log:

  • Need to fetch prune first or this bombs on branches you think exist but do not.
  • Added file to clean up local branches.
  • Skip Rel and Emer branches since they require more thought.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.