Skip to content

Instantly share code, notes, and snippets.

@jjb
Created February 6, 2024 16:36
Show Gist options
  • Save jjb/81b12fefb67d10eb3486fae08fafa734 to your computer and use it in GitHub Desktop.
Save jjb/81b12fefb67d10eb3486fae08fafa734 to your computer and use it in GitHub Desktop.
git cleanup
[alias]
delete-squashed = "!f() { local targetBranch=${1:-master} && git checkout -q $targetBranch && git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ \"--format=%(refname:short)\" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == \"-\"* ]] && git branch -D $branch; done; }; f"
#!/usr/bin/env sh
git fetch origin
git checkout master
git pull
echo ">>>>> prune"
git remote prune origin
echo ">>>>> delete merged"
git branch --merged master | grep -v master | xargs -n 1 git branch -d
echo ">>>>> delete squashed"
git delete-squashed
echo ">>>>> gc"
git gc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment