Skip to content

Instantly share code, notes, and snippets.

@bozdoz
Last active August 1, 2023 13:47
Show Gist options
  • Save bozdoz/25ebb60c2e7bfa14f2cba3a593b67ec1 to your computer and use it in GitHub Desktop.
Save bozdoz/25ebb60c2e7bfa14f2cba3a593b67ec1 to your computer and use it in GitHub Desktop.
find remote branches that have diverged by some amount of commits
git ls-remote --heads origin | while read sha ref; do
behind=`git rev-list $sha..master --count`
if [ $behind -ge 1000 ]; then
echo "$ref $behind";
fi
done
@bozdoz
Copy link
Author

bozdoz commented Aug 1, 2023

To delete the branches, strip the "refs/heads/" and call git push origin --delete:

if [ $behind -ge 1000 ]; then
  git push origin --delete "${ref/refs\/heads\//}"; 
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment