Skip to content

Instantly share code, notes, and snippets.

@whylom
Created June 29, 2012 13:58
Show Gist options
  • Save whylom/3018099 to your computer and use it in GitHub Desktop.
Save whylom/3018099 to your computer and use it in GitHub Desktop.
git purge (delete unmerged branches starting with "_")

When using Git, I find myself doing a lot of what I call "exploratory merging" into a throwaway local branch. This is to preview what a scary merge might look like master, or to isolate a bug in a staging environment by selectively merging in certain of the branches that have been deployed.

The names of my throwaway branches always start with an underscore, so I can easily see them when I git branch. Below is a Bash one-liner (aliased as git purge) that deletes unmerged branches whose names start with "_".

[alias]
  purge   = !git branch --no-merged | tr -d "* " | grep ^_ | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment