Skip to content

Instantly share code, notes, and snippets.

@junderw
Created April 9, 2019 09:20
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 junderw/bf746e0a721e8a1a85d5cadbd2519a9f to your computer and use it in GitHub Desktop.
Save junderw/bf746e0a721e8a1a85d5cadbd2519a9f to your computer and use it in GitHub Desktop.
Some commands for cleaning up my git folders... too many branches over time.
# Get rid of remotes
git fetch --prune --all
# Check branches for stuff you might want to keep
# This will show branches that are NOT on the remote for origin or upstream
git branch | grep -v "$(git branch --remote | grep -e "origin/\|upstream/" | grep -v "\->" | cut -d/ -f2)"
# Here's another one to check. checks your local master and gives any branches that are merged to master
git branch --merged=master | grep -v master
# Get rid of local branches not on origin or upstream
# WARNING THIS MIGHT LOSE YOUR WORK, CHECK THE ABOVE FIRST
git branch -D $(git branch | grep -v "$(git branch --remote | grep -e "origin/\|upstream/" | grep -v "\->" | cut -d/ -f2)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment