Delete a local branch
Medium risk
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Deletes a fully merged local branch. Refuses to delete a branch whose commits are not reachable from the current branch, so no work is lost.
gitbranchdelete
Parameters
Name of the local branch to delete.
Commands
Confirm the branch is merged and safe to delete
git branch --mergedDelete the merged local branch
git branch -d <branch_name>Verification
git branch --list <branch_name>No output; the branch no longer exists locally.
Undo
Recreate the branch at the hash printed by the delete command ("Deleted branch ... (was <hash>).")
git branch <branch_name> <hash>Pitfalls
- git branch -d refuses unmerged branches; -D force-deletes and can strand unmerged commits.
- If the deletion hash is lost, find it with git reflog or use the recover deleted branch recipe.
- Only the local branch is removed; the remote branch of the same name is untouched.