← Git from Scratch
Lesson 13 of 17 · 10 XP
Deleting branches
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
Once a branch has been merged, it's no longer needed. The commits won't go anywhere: they're already in main.
git branch -d feature # delete a merged branch
git branch -D experiment # force-delete, even one that is NOT merged (its commits will be lost!)
Git won't let you delete the branch you're currently on, and -d refuses to delete an unmerged branch. This protects you from losing work.
Deleting a branch on GitHub is a separate action: git push origin --delete feature, or the button after a Pull Request is merged.
It's a good habit to clean up old branches regularly, so that git branch stays short and clear.
Task. The feature branch has already been merged into main. Delete it.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.