</>
Skip to content
Git lessons (18/44)

Git — Delete Branch

Delete Merged Branch

git branch -d branch-name

Force Delete

git branch -D branch-name

Delete Remote Branch

git push origin --delete branch-name

Delete Multiple Branches

git branch -d branch1 branch2 branch3

Delete Merged Branches

# Delete local branches merged into main
git branch --merged main | grep -v "main" | xargs git branch -d

Before Deleting

# Check if branch is merged
git branch --merged

# Check branch status
git branch -v

Safety

FlagDescription
-dSafe delete (checks merge)
-DForce delete (no check)

Mini Practice

  1. Delete a merged branch
  2. Force delete a branch
  3. Delete remote branch
  4. Clean up merged branches

Up Next

Continue with Merge Branch — merging branches together.

Related Topics

Frequently Asked Questions about Delete Branch

What is Delete Branch in Git?

Delete Branch is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Delete Branch?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Delete Branch.

Why is Delete Branch important in Git?

Delete Branch is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.