Skip to content

Instantly share code, notes, and snippets.

@stefanofiorentino
Last active December 23, 2021 08:43
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 stefanofiorentino/ed6bd40424016054e2a090a71cd460d4 to your computer and use it in GitHub Desktop.
Save stefanofiorentino/ed6bd40424016054e2a090a71cd460d4 to your computer and use it in GitHub Desktop.
git script to add to $PATH to be launched by `git gone` or `git gone --force` (it only print commands to issue)
#!/bin/bash
git fetch
REMOTE=origin
if [ $# -ge 1 ]; then
REMOTE=$1
fi
echo "Pruning ${REMOTE}: $#"
if [[ $* == *--force* ]]
then
git remote prune ${REMOTE} && git branch -vv | cut -c 3- | grep ': gone]' | awk '{print $1}' | xargs -n1 -r echo git branch -D
else
git remote prune ${REMOTE} && git branch -vv | cut -c 3- | grep ': gone]' | awk '{print $1}' | xargs -n1 -r echo git branch -d
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment