Ad space (banner)
🌿Git Lessons
Lesson 19 / 59

Deleting a Branch with git branch -d

This lesson covers deleting a branch you no longer need with git branch -d. It's for anyone searching "git branch -d usage."

git branch -d deletes a branch once you're done using it. Once a branch's work is finished and merged into the main branch, deleting it for tidiness is standard practice.

In Try It, run git branch -d feature. The branch named feature is deleted, and your repository's branch list stays nice and tidy.

A common early mistake is hitting an error trying to delete a branch that hasn't been merged yet — Git refuses to delete an unmerged branch, for safety. To force it anyway, use the uppercase -D flag instead. In real teams, regularly deleting branches once their feature work is done keeps the branch list readable and keeps team development running smoothly.

Git
Try it (type this into the pseudo terminal)
git branch -d feature

🧑‍💻 You can type this command into the Git pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)