Skip to content

Instantly share code, notes, and snippets.

@JeffBelback
Last active December 27, 2021 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JeffBelback/55cd20c8e721ef7fd1f2e6e9f12bff6d to your computer and use it in GitHub Desktop.
Save JeffBelback/55cd20c8e721ef7fd1f2e6e9f12bff6d 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