Skip to content

Instantly share code, notes, and snippets.

@valtoni
Created July 20, 2018 19:49
Show Gist options
  • Save valtoni/48c5e8ac2720cadf76e2aec1422d3951 to your computer and use it in GitHub Desktop.
Save valtoni/48c5e8ac2720cadf76e2aec1422d3951 to your computer and use it in GitHub Desktop.
Script to delete branches without remote upstream
#!/bin/sh
while read branch; do
upstream=$(git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null)
if [[ $? == 0 ]]; then
echo $branch tracks $upstream
else
echo $branch has no upstream configured
git branch -D $branch
if [ -z $? ]; then
echo $branch was successfull deleted
else
echo "$branch was not fully merged. Force it change to -D in script"
fi
fi
done < <(git for-each-ref --format='%(refname:short)' refs/heads/*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment