Last active
July 3, 2021 09:40
-
-
Save standaniels/7c1146b84be5e3eb277bf32db624ea01 to your computer and use it in GitHub Desktop.
Prune local branches that do not exist on the remote anymore.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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