How to Delete all branches except one in GIT?

0 votes
163 views
asked Sep 11 by Hitesh Garg (346 points)  

I want to delete all the branches on local except the current one. Is this possible with a single command?

1 Answer

0 votes
answered Sep 24 by Hitesh Garg (346 points)  
 
Best answer

The way to delete all the local branches except the one you want -

git branch | grep -v "branch_to_skip_deletion" | xargs git branch -D

Replace "branchtoskip_deletion" with the branch name you don't want to delete and this command will remove all the local branches except the mentioned one.

Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...