Skip to content

Instantly share code, notes, and snippets.

@phillijw
Created July 10, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillijw/98b54553a557bdb9dec9e56b7a58e916 to your computer and use it in GitHub Desktop.
Save phillijw/98b54553a557bdb9dec9e56b7a58e916 to your computer and use it in GitHub Desktop.
git cleanup alias
Calling "git cleanup" will delete local branches that have already been merged into origin/master. It skips master, staging, and dev because we don't want to delete those in normal circumstances.
$ git config --global alias.cleanup '!git branch --merged origin/master | egrep -v "(^\*|master|staging|dev)" | xargs git branch -d'
@phillijw
Copy link
Author

Then just call it with git cleanup

@phillijw
Copy link
Author

The ^\* is checking to make sure it doesn't try to delete the current branch you're on (which gets displayed with a * next to the name)

@phillijw
Copy link
Author

Experiment using this command in a terminal: git branch --merged origin/master | egrep -v "(^\*|master|staging|dev)" | xargs echo

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