Skip to content

Instantly share code, notes, and snippets.

@irontoby
Last active February 12, 2021 20:31
Show Gist options
  • Save irontoby/3f62f9eac2a0d00e4a42939ff4f81ca5 to your computer and use it in GitHub Desktop.
Save irontoby/3f62f9eac2a0d00e4a42939ff4f81ca5 to your computer and use it in GitHub Desktop.
Git "Deep Clean"
#!/bin/bash
# does a better job of cleaning unreachable stuff
git reflog expire --expire-unreachable=2.weeks.ago
git gc --prune=now
#!/bin/bash
echo Removing local branches which have already been merged at remote...
git-purge-remote-merged.sh
echo Removing local branches which were created to track remotes, when remote is now gone...
git-remove-local-with-pruned-remote.sh
echo Deep prune...
git-better-clean.sh
#!/bin/bash
# remove local branches which have already been merged at remote
git remote prune origin
git branch --merged | egrep -v "(^\*|master|main|dev|core|hotfix)" | xargs --no-run-if-empty git branch -d
#!/bin/bash
# remove local branches which were created to track remotes, when remote is now gone
git branch -vv | perl -ne 'print unless m/^[+*]/;' | grep ': gone]' | tee /dev/tty | awk '{print $1}' | xargs --no-run-if-empty git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment