Created
August 3, 2017 06:46
-
-
Save danken00/017e519ab9d567ddaf17484e15d5375d to your computer and use it in GitHub Desktop.
Cleaning up local Git repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check there's nothing that hasn't been committed and synced | |
git status; | |
// Push to the remote to make sure it has a record of any local commits/branches | |
git push; | |
// Now, prune your local repos | |
git remote prune origin; | |
// And clean up any tracked branches not in the list of remotes (https://stackoverflow.com/questions/13064613/how-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore) | |
// WANRING: `-D` _force_ deletes your branches, so do a dry run if you want to make sure nothing important is going bye-bye | |
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment