bashbeginner
Delete Remote Git Branch
Commands to delete local and remote branches, prune stale references, and clean up merged branches.
bashPress ⌘/Ctrl + Shift + C to copy
# 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.
bashbeginner
Rename Git Branch (Local and Remote)
Commands to rename a local and remote Git branch including updating tracking references.
Best for: Fixing branch naming convention mistakes
#git#branch
bashbeginner
Git Clone Specific Branch
Clone a specific branch from a remote repository without fetching all branches and history.
Best for: Cloning only a deployment branch for CI/CD
#git#clone
bashintermediate
Git Repository Cleanup and Maintenance
Commands for cleaning untracked files, pruning refs, optimizing repo size, and maintenance tasks.
Best for: Reducing repository size and improving performance
#git#cleanup
bashbeginner
Git Remote Prune and Branch Cleanup
Clean up stale remote-tracking branches and local branches that have been merged or deleted upstream.
Best for: Keeping local repository tidy
#git#cleanup