Skip to content

Instantly share code, notes, and snippets.

@samrocketman
Created April 5, 2017 16:41
Show Gist options
  • Save samrocketman/be901bc0542a47c6870045f694178269 to your computer and use it in GitHub Desktop.
Save samrocketman/be901bc0542a47c6870045f694178269 to your computer and use it in GitHub Desktop.
Clean up git branches

Fetch the branches

From a remote repository fetch branches.

mkdir ~/sandbox
cd ~/sandbox
git clone your-repository
cd your-repository/
git checkout origin/master
git fetch origin '+refs/heads/*:refs/heads/*'
git checkout master
#show branches which have been merged to master
git branch --merged master
#show branches which have not been merged to master
git branch --no-merged master

Clean up the branches

( set -x; git branch --merged master | grep -v -- '*' | while read x; do git push origin ":refs/heads/$x";done; set +x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment