DEV Community

loading...
Student Edge

How to remove local branches that have been closed on master

prayatna profile image Prayatna Bhattarai ・1 min read

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

Discussion (0)

pic
Editor guide