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
Enter fullscreen mode Exit fullscreen mode

🦄 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
Enter fullscreen mode Exit fullscreen mode

👍 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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)