Skip to content

Instantly share code, notes, and snippets.

View standaniels's full-sized avatar

Stan Daniëls standaniels

View GitHub Profile
@standaniels
standaniels / git-prune.sh
Last active July 3, 2021 09:40
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