Skip to content

Instantly share code, notes, and snippets.

@standaniels
Last active July 3, 2021 09:40
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 standaniels/7c1146b84be5e3eb277bf32db624ea01 to your computer and use it in GitHub Desktop.
Save standaniels/7c1146b84be5e3eb277bf32db624ea01 to your computer and use it in GitHub Desktop.
Prune local branches that do not exist on the remote anymore.
#!/bin/bash
function gprune() {
for branch in $(git branch --no-color --list --format='%(refname:short)'); do
# Keep branch if it exists on remote or if it's the current.
if git show-branch remotes/origin/$branch >/dev/null 2>&1 || [[ $(git branch --show-current) = $branch ]]; then
echo "✅ $branch";
else
git branch -D $branch > /dev/null && echo "❌ $branch";
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment