DEV Community

Prayatna Bhattarai for Student Edge

Posted on

3 1

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay