Created
September 14, 2023 21:24
-
-
Save manoj-choudhari-git/aecfa7f35de91129775d70ba9bbb5c7f to your computer and use it in GitHub Desktop.
Git - PowerShell Script to Clean up Local Merged Branches
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
## Checkout the main branch | |
## If your main branch name is different, use that name instead of 'main' | |
git checkout main | |
## This will remove the branches | |
## which are present on local but are deleted on remote | |
git fetch --prune | |
## The below command will get all branches which are merged | |
## Then it will remove the names 'main', 'master', 'develop' from the list | |
## Then for each branch name, it will run git branch delete command | |
git branch --merged ` | |
| Where-Object { $_ -notmatch "^(\\*|main|master|develop)" } ` | |
| ForEach-Object { git branch -d $_.Trim() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment