DEV Community

Discussion on: 5 Git Tricks Every Developer Should Know

Collapse
 
moopet profile image
Ben Sinclair

git branch | grep -v “master” | xargs git branch -D will delete branches that haven't been merged, which is potentially dangerous. I'd use -d instead, as you suggest in your fourth point, and if you end up with a couple of branches left over, you can delete them one at a time after you're sure you don't need them any more.

Collapse
 
lucassperez profile image
Lucas Perez • Edited

It will also keep branches that include the word master in it. If for some reason you have branches named like "not-master", then it is better to stay sharp! 😅

Collapse
 
shadid12 profile image
Shadid Haque

Good point 👍🤠

Collapse
 
jessekphillips profile image
Jesse Phillips

git switch --detach origin/master
git branch --merged | xargs git branch -d

That would be another good choice. It has some of my additions.

  • delete your local master, don't put unneeded work to manage it
  • utilize detached head, it is not scary