How to delete a Git branch locally and remotely?
Delete a local branch
Safe delete (recommended)
Deletes the branch only if it’s already merged.
git branch -d branch_name
Force delete (even if not merged)
Use this carefully:
git branch -D branch_name
Delete a remote branch
git push origin --delete branch_name
Delete local + remote together (common workflow)
git branch -d branch_name
git push origin --delete branch_name
Important
- You cannot delete the branch you are currently on
git checkout main
- Replace branch_name with your actual branch name
- origin is the default remote — change it if needed
Verify deletion
List local branches
git branch
List remote branches
git branch -r
Clean up stale remote branches
git fetch -p
Quick Action Command
- Delete local (safe):
git branch -d branch - Delete local (force):
git branch -D branch - Delete remote:
git push origin --delete branch - Cleanup:
git fetch -p
Top comments (0)