Trimming local git branches
Every now and then I remember to clean local, and merged git branches, and I always forget how to do it. So, TIL how to think about it, thanks to this post.
Get on the
Run a script using the following procedure:
- List all of the branch names
- Look for the asterisk (*) and ignore it (make sure it’s verbose)
- Pass all of the other branches and run the git branch deletion command
Here’s how it looks.
git checkout main && \ git branch | \ grep -v '^*' | \ xargs git branch -d
I’ve created and alias in
.zshrc for this command as
git-trim. Enjoy, future Dave!