Branches and merges
Delete a finished branch
Remove a local branch name after its useful commits have been merged.
After you merge add-search into main in notes-project, the branch name is just clutter. The commits already live on main. You can delete the name without losing the work.
I delete finished branches regularly. A long list of stale names makes git branch harder to read.
First, stand on main and check that it reaches the merged commits:
git switch main
git log --oneline --decorate --graph --all
You should see the feature commits on the path from main, with add-search still pointing at the same tip or behind main after a fast-forward merge.
Delete the local branch name:
git branch -d add-search
Git prints:
Deleted branch add-search (was abc1234).
The lowercase -d is deliberately cautious. Git refuses when the branch tip is not merged.
Try deleting before merging and Git stops you:
error: the branch 'add-search' is not fully merged
That refusal is a feature. Inspect the graph with git log --oneline --graph --all. If the work truly belongs on main, merge first, then run -d again.
Another case: you switched away from add-search but never merged. git branch still lists it. Stand on main, run git merge add-search, verify with git log --oneline -3, then delete with -d.
Do not reach for uppercase -D just because -d refused. -D forces deletion even when commits are not merged. They can become hard to find without a branch name pointing at them.
After a safe deletion, check what remains:
git branch
git log --oneline --decorate --graph --all
git branch should list only main. The graph should still show the merged commits reachable from main. The commit message from add-search still appears in git log main.
Remote branches are separate. Deleting local add-search does not delete origin/add-search on GitHub. Remove the remote branch from the hosting site if your team expects that cleanup.
Try this in notes-project: delete add-search before merging, read the refusal, merge the branch, then delete safely with -d.
Lesson completed