DEV Community

Goffity Corleone
Goffity Corleone

Posted on • Updated on

Delete git branch not in remote

I'm not sure where I received the information, but it was most likely from stackoverflow.

git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d
Enter fullscreen mode Exit fullscreen mode

Update 2022-08-02

git checkout develop && git branch --merged | grep -v 'main' | grep -v 'develop' >/tmp/merged-branches && vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches
Enter fullscreen mode Exit fullscreen mode

Ref: https://stackoverflow.com/questions/7726949/remove-tracking-branches-no-longer-on-remote

Top comments (0)