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)