Branches & Tags

How to Delete a Remote Branch in Git

Delete a branch from remote origin (GitHub, GitLab, Bitbucket) after a pull request has been merged.

Instant 1-Line Solution
Reversible (History Change)Beginner
git push origin --delete <branch-name>
When to use this scenario:A feature branch was merged into main and you want to clean up remote branches to keep the repository tidy.

Step-by-Step Execution Guide

1Delete remote branch
git push origin --delete feature-branch

Sends a delete command to remote origin for the specified branch.

2Delete local branch
git branch -d feature-branch

Safely deletes the local branch if it has already been merged.

3Force delete unmerged local branch
git branch -D feature-branch

Forces deletion of local branch even if not fully merged into current branch.

4Prune stale remote-tracking branches
git fetch --prune

Removes local references to remote branches that were deleted by other team members.

Critical Pitfalls & Precautions

  • β€’Cannot delete the remote branch if it is set as the repository's Default Branch on GitHub/GitLab.
Frequently Asked Questions

Delete Remote Branch - Frequently Asked Questions

Common questions about safe rollback, remote history implications, and troubleshooting.

Git keeps cached references locally. Run "git remote prune origin" or "git fetch --prune" to synchronize and clean them.