-
-
Save rogeriopradoj/1737740a7e0293d70edf678bc38bd95f to your computer and use it in GitHub Desktop.
Mass remove local git branches and prune remote tracking
This file contains 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
// List all remotely tracked branches that do not exist in the remote repo | |
git remote prune origin --dry-run | |
// Prune all remotely tracked branches that do not exist in the remote repo | |
git remote prune origin | |
// List all local branches that were merged into master, explicitly exclude master from that list | |
git branch --merged master | grep -v 'master' | |
/* | |
Delete local branches | |
Each command does not delete master | |
*/ | |
// Delete all local branches that were merged into master | |
git branch --merged master | grep -v 'master' | xargs git branch -d | |
// Safe deletion of all local branches (branches not merged into master will not get purged) | |
git branch | grep -v 'master' | xargs git branch -d | |
// Force delete of all local branches | |
git branch | grep -v 'master' | xargs git branch -D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment