Merge and delete branch in one step/command

BendEg picture BendEg · Feb 19, 2016 · Viewed 35.6k times · Source

Is it possible, to merge a branch and automatically delete it with a single command? The delete step should only be executed if merging was successful.

Answer

Zbynek Vyskovsky - kvr000 picture Zbynek Vyskovsky - kvr000 · Feb 19, 2016

No, git doesn't support this at the same time.

However, you can run the commands in a shell conditionally:

git merge source-branch && git branch -d source-branch

Edit:

-d will only remove merged branches while -D will also remove unmerged branches, so -d will ensure that the branch is merged and you don't delete a branch by accident.