DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on • Updated on

[Git] delete the [Local | Remote] merged branch

🔗 Parent Note

Delete Local Branch

👍 Usual way

git branch --merged lists branch that is merged into the current branch.
so, this deletes merged branches.

git branch --merged | grep -v master | xargs git branch -d

🦄 Delete Squashed Merged Branch

Only 3 steps.

# show local branches
$ git branch
  * master
    branch1
    branch2
    branch3

# grep them
$ git log | grep 'branch1\|branch2\|branch3'
   Merge branch 'branch2' into 'master'

# force delete it
$ git branch -D branch2

👍 Delete Remote Branch

# delete remote branches with some conditions
git branch --remote | grep -v "upstream" | egrep -v "origin/master|origin/deployment" | xargs git branch -dr

Top comments (0)