Branches and merges
Delete a finished branch
Remove a local branch name after its useful commits have been merged.
8 minute lesson
After merging a feature, verify that the current branch reaches its commits:
git log --oneline --decorate --graph --all
Then delete the local branch name:
git branch -d add-search
The lowercase -d is deliberately cautious. Git refuses to delete the branch when its tip is not merged into an appropriate upstream or HEAD.
When the branch was merged, its commits remain reachable through main. You are deleting one reference, not the completed work.
Do not reach for uppercase -D just because deletion was refused. It forces the reference deletion and can leave commits without an ordinary branch name. Inspect the graph and decide whether the work is truly disposable.
After deletion, check the remaining references:
git branch
git log --oneline --decorate --graph --all
Exercise: create an unmerged practice branch and try git branch -d. Read the refusal, merge the branch, then repeat the safe deletion.
Lesson completed