DEV Community

Prayatna Bhattarai for Student Edge

Posted on

How to remove local branches that have been closed on master

In Git Bash/ Git CLI run the commands as follow (from whichever branch you are currently on):

git remote prune origin
Enter fullscreen mode Exit fullscreen mode

Then:

  • checkout master
  • update it

and run in Git Bash/ Git CLI:

$ git branch --merged | grep -v "\*" | xargs -n 1 git branch -
Enter fullscreen mode Exit fullscreen mode

And that's it!

To delete all local branches except master:

$ git branch | grep -v "master" | xargs git branch -D
Enter fullscreen mode Exit fullscreen mode

Some commands to a further clean up: Git clean

Top comments (0)