Delete a merged branch

Description: The branch feature-menu is merged into main. Show the merged branches and delete it.

Hint:

  • git branch --merged lists merged branches. -d is the safe delete.

Solution

Terminal output

$ git branch –merged
feature-menu
* main
$ git branch -d feature-menu
Deleted branch feature-menu (was cda1bfa).
$ git branch
* main

How it works

  • The safe delete -d works only when the branch is merged. Otherwise Git refuses.
  • The commit is not lost, because it is already part of main.

Read Git Branch.


Learn more about the similar topics:
Tutorials
Git Branch
Git Checkout and Switch
Git Merge
Git Merge Conflict
Git Rebase
Git Cherry Pick
Git Branching Strategy
Exercises & Assignments
Create a new branch and switch to it
Merge a feature branch into main
Resolve a merge conflict
Delete a merged branch
Rename a local branch
Copy one commit to another branch with cherry-pick
Interview Questions & Answers
How you can see list of all branches in Git?
How do I create a new branch in Git?
How to switch to an another branch in Git?
How to merge one branch to another in Git?
How to rename a local Git branch?
What is the difference between git merge and git rebase?
What is a merge conflict and how do you resolve it?