This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Wahid Abduhakimov
It's no secret that we end up with tons of unused, stale branches (either merged or not) in local git repository.
You might want to clean-up unused branches for both organization and storage purposes. But you don't want to delete branches one-by-one which would literally take hours (sometimes).
Here is how to remove local branch in bulk.
1. Remove git branches on *nix terminal
.
# this will delete only merged branches
git branch --merged | grep -v \* | xargs git branch -D
# this will delete all branches except the current one checked out
git branch | grep -v \* | xargs git branch -D
2. Remove git branches on Windows Powershell/Terminal
.
# this will magically all branches except dev, main, master and develop.
git branch | Select-String -Pattern '^(?!.*(dev|main|master|develop)).*$' | ForEach-Object { git branch -D $_.ToString().Trim() }
# this will only delete merged branches.
git branch --merged | Select-String -Pattern '^(?!.*(dev|main)).*$' | ForEach-Object { git branch -D $_.ToString().Trim() }
Yeah, it's that easy. Go ahead and give your local git some breathe 🙂.
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Wahid Abduhakimov
Wahid Abduhakimov | Sciencx (2022-09-22T15:49:11+00:00) Remove local stale branches. Retrieved from https://www.scien.cx/2022/09/22/remove-local-stale-branches/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.