Delete Remote Git Branch
Commands to delete local and remote branches, prune stale references, and clean up merged branches.
# Delete a remote branch
git push origin --delete feature/old-branch
# Delete a local branch (safe — only if merged)
git branch -d feature/old-branch
# Force delete a local branch (even if not merged)
git branch -D feature/old-branch
# Delete all local branches merged into main
git checkout main
git branch --merged | grep -v 'main\|master\|\*' | xargs -r git branch -d
# Prune remote tracking branches that no longer exist
git fetch --prune
# Prune and list what was removed
git remote prune origin --dry-run
git remote prune origin
# List all remote branches
git branch -r
# List branches merged/not merged into main
git branch --merged main
git branch --no-merged mainUse Cases
- Cleaning up after merged pull requests
- Removing stale feature branches
- Repository housekeeping and maintenance
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Rename Git Branch (Local and Remote)
Commands to rename a local and remote Git branch including updating tracking references.
Git Clone Specific Branch
Clone a specific branch from a remote repository without fetching all branches and history.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.