Branches · practice
Remove a Finished Branch Safely
The clearer-title. Someone made it to work on the guide’s title, and that work is done: the Clarify the guide title, is the very commit main points at now. The name has outlived its purpose, and a repository collects these quickly if nobody tidies up.
Removing it takes nothing away from the project, because a branch name was never where the work lived.
Check before deleting the name
Start with the plain branch list:
git branch
You should be on main. The list should also contain add-opening-hours, which protects your separate commit, and clearer-title, the finished branch you are about to remove.
The command git branch -d clearer-title uses git branch to manage the named branch. The option -d means delete with a safety check. Git refuses this form when the branch has commits that are not retained by your current history.
Run the safe form:
git branch -d clearer-title
git branch
The second list no longer contains clearer-title. It still contains main and add-opening-hours.
Only the finished branch name was deleted. The baseline commits remain reachable through main, and the separate opening-hours commit remains reachable through add-opening-hours. This is why deleting a fully retained branch is different from deleting a folder full of copied work.
Leave add-opening-hours alone, though. Its newest commit is not part of main, so deleting that name is the one case where you would genuinely be stranding work. Git would stop you anyway: -d refuses exactly that situation, which is what makes it the safe form to reach for by default.
Why is git branch -d clearer-title safe in this repository?
You now have the full beginner branch loop: read branch names, create and switch to one, make a commit that moves only that branch, return to main, and remove a finished branch with Git’s safety check. Combining separate histories belongs to the next chapter on merging.