Skip to content

Instantly share code, notes, and snippets.

@moxley
Created July 13, 2020 18:30
Show Gist options
  • Save moxley/c24b285576fc3d9f75a580a5392cbf90 to your computer and use it in GitHub Desktop.
Save moxley/c24b285576fc3d9f75a580a5392cbf90 to your computer and use it in GitHub Desktop.
Script that cleans up local repo after merging a PR
#!/bin/sh
# Example:
# gclean master
trunk="$1"
if [ -z "${trunk}" ]; then
echo "Usage: $0 TRUNK"
exit 2
fi
if ( git branch | grep "$trunk" ); then
true
else
echo "Did not find $trunk"
exit 2
fi
git checkout "$trunk"
git pull
git branch --merged | egrep -v "(^\*|$trunk)" | xargs git branch -d
git branch -r --merged | egrep -v "(^\*|$trunk)" | xargs git branch -r -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment