Skip to content

Instantly share code, notes, and snippets.

@rydurham
Created December 21, 2023 16:56
Show Gist options
  • Save rydurham/61e1ae3ccf353524077d696cb86f8245 to your computer and use it in GitHub Desktop.
Save rydurham/61e1ae3ccf353524077d696cb86f8245 to your computer and use it in GitHub Desktop.
Git - Purge Old Branches
# https://stevenharman.net/git-clean-delete-already-merged-branches
git_purge() {
# have any arguments been passed?
if [ $# -gt 0 ];then
BRANCH=$1
echo $BRANCH
git checkout $BRANCH
git branch --merged $BRANCH | grep -v "\* $BRANCH" | xargs -n 1 git branch -d
git remote prune origin
else
echo "No branch specified"
fi
}
alias gp=git_purge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment