Skip to content

Instantly share code, notes, and snippets.

@jpukg
Forked from JeffBelback/delete-old-branches.sh
Created December 27, 2021 21:47
Show Gist options
  • Save jpukg/ac498b17e5b316808284d1dbf72a9edc to your computer and use it in GitHub Desktop.
Save jpukg/ac498b17e5b316808284d1dbf72a9edc to your computer and use it in GitHub Desktop.
Git helper functions
#!/bin/bash
# Deletes branches that have been removed on origin
function no_remote() {
if git rev-parse --git-dir >/dev/null 2>&1; then
git fetch --prune
echo "Branches with no remote:"
git branch -vv | cut -c 3- | awk '$3 !~/\[/ { printf " %s\n", $1 }'
echo -e "\nDeleting branches with deleted remote:"
del=$(git branch -vv | awk '$4 ~/gone\]/ { printf "git branch -D %s && ", $1 }')
del="$del echo \"Complete\""
bash -c "$del"
else
echo "Not a git repository"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment