0

What is the best way to remove branch references that no longer exist and delete local branches already merged for git repos in Windows command prompt (i.e. not using bash)?

David Momenso
  • 1,781
  • 1
  • 11
  • 9
  • 2
    Possible duplicate of [How can I delete all Git branches which have been merged?](https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged) – trejas Dec 28 '17 at 17:05

1 Answers1

0

This will first remove any remote tracking references that no longer exist and then proceed to enumerate and remove already merged local branches. The exception is that current, develop and master branches will be kept.

git fetch -p && for /f "tokens=1,2" %b in ('git branch --merged ^| findstr /v /c:"master" /c:"develop" /c:"*"') do (git branch -d %b)
David Momenso
  • 1,781
  • 1
  • 11
  • 9