Skip to content

Instantly share code, notes, and snippets.

@iainconnor
Last active October 20, 2017 21:05
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 iainconnor/b5ef2c0e216ad26a748dd97721300720 to your computer and use it in GitHub Desktop.
Save iainconnor/b5ef2c0e216ad26a748dd97721300720 to your computer and use it in GitHub Desktop.
Custom cleanup command for git.
#!/bin/sh
source "$(git --exec-path)/git-sh-setup"
if git diff-index --quiet HEAD --; then
git checkout master
git remote update origin --prune
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote &> /dev/null; done
git pull --all
git branch -r --merged master | grep -v master | sed 's/origin\///' | xargs -n 1 git push --delete origin &> /dev/null
git branch --merged master | egrep -v "(^\*|master)" | xargs -n 1 git branch -d &> /dev/null
else
echo "You have pending changes. Finish them before cleaning up."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment