Skip to content

Instantly share code, notes, and snippets.

@wyeo
Last active April 24, 2020 11:39
Show Gist options
  • Save wyeo/d56e5daae83f8724e9dbb1b281fa5789 to your computer and use it in GitHub Desktop.
Save wyeo/d56e5daae83f8724e9dbb1b281fa5789 to your computer and use it in GitHub Desktop.
Remove unsed git local branches

One-line command

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

  • git branch –merged : first, you are simply listing all the branches currently merged with your current checked out branch;
  • egrep -v “(^*|master|dev)” : you are using the invert matching feature of grep in order to exclude any branches that may be called “master” or “dev”, just in case;
  • xargs git branch -d : you are deleting every single branch listed before.

Source

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