Delete a Git Branch Locally and Remotely
How to Delete a Git Branch Locally and Remotely: A Step-by-Step Guide
Published by Carlo van Wyk on June 15, 2025 in Git

Deleting Git branches locally and remotely requires different commands, but the process is straightforward.
Delete a Local Git Branch
To delete a local branch that has been merged, use:
git branch -d branch_name
The lowercase 'd' is the "safe" delete that only works if the branch has been merged into the current branch or upstream branch. Git checks that you won't lose any commits before deleting.
To delete a local branch that has not been merged yet, force delete with:
git branch -D branch_name
The uppercase 'D' is a "force" delete that bypasses all safety checks. It will delete the branch regardless of merge status, potentially causing you to lose commits that exist only on that branch.
Delete a Remote Git Branch
To delete a remote branch
, use either of these equivalent commands:
git push origin --delete branch_name
or
git push origin :branch_name
Verify Branch Deletion
Check local branches:
git branch
Check remote branches:
git branch -r
Clean Up References
If deleted remote branches still appear in your local repository, update references with:
git fetch --prune
or
git remote prune origin