DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on • Edited 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)