Skip to content

Instantly share code, notes, and snippets.

@trashhalo
Forked from schacon/gist:942899
Last active August 29, 2015 13:56
Show Gist options
  • Save trashhalo/8871121 to your computer and use it in GitHub Desktop.
Save trashhalo/8871121 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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