ลบ branch ทุก branch ใน git local

ลบ branch ทุก branch ใน git local

หากทำงานกันหลายคนใน Git project นั้นๆ เราก็จะมีการ pull branch ใหม่ๆ ลงมาที่เครื่องเรา และมันจะทำให้ branch เยอะขึ้นเรื่อยๆ ผมเลยไปหาคำสั่งที่ไว้ลบ branch ทั้งหมดออก เวลาเราเรียก git branch แล้วจะได้ดูง่ายขึ้นหน่อย

$ git branch -D `git branch --merged | grep -v \* | xargs` 

หรือ

$ git branch --merged | grep -v \* | xargs git branch -D

เพียงเท่านี้ เราก็จะเหลือ branch ที่เราอยู่ ณ. ปัจจุบันแล้ว

Thanks: stackoverflow.com/questions/10610327/delete-all-local-git-branches

Arnon Kijlerdphon

Arnon Kijlerdphon

Choosing to live a plant-based lifestyle for the animals, my health, and the future of our planet.
Bangkok, Thailand