This content originally appeared on DEV Community and was authored by Daniel Teixeira
This is a simple script that I use to remove local branches that are no longer on the origin. Just to clean my local env.
git remote prune origin
git branch -vv | grep ': gone]' | grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d
You can also create an alias and add to your .bashrc (if you use Linux or macOS).
Edit ~/.bashrc file.
Add this in the end of the file:
alias git-clean="git remote prune origin; git branch -vv | grep ': gone]' | grep -v \"\*\" | awk '{ print $1; }' | xargs -r git branch -d;"
Reload bash: source ~/.bashrc
That's all. :)
This content originally appeared on DEV Community and was authored by Daniel Teixeira

Daniel Teixeira | Sciencx (2025-02-04T17:54:52+00:00) Remove local branches that are no longer in the origin. Retrieved from https://www.scien.cx/2025/02/04/remove-local-branches-that-are-no-longer-in-the-origin/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.