Skip to content

Instantly share code, notes, and snippets.

@MichaelPereira
Created September 9, 2016 14:52
Show Gist options
  • Save MichaelPereira/7ce7c73d2f7325cf08da8450fdf10d94 to your computer and use it in GitHub Desktop.
Save MichaelPereira/7ce7c73d2f7325cf08da8450fdf10d94 to your computer and use it in GitHub Desktop.
Script to clean-up remote branches that have already been merged to master.
#!/bin/bash
# Format for excluded branches: "branch|branch|branch..."
excluded_branches="master|gh-pages|HEAD"
for branch in $(git branch -r | tr -d ' ' | sed -e 's/->.*//' | egrep -v "${excluded_branches}"); do
if git branch -r --contains "${branch}" | grep -q master; then
git push origin ":${branch#origin/}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment