bashbeginner

Delete Remote Git Branch

Commands to delete local and remote branches, prune stale references, and clean up merged branches.

bash
# 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 main

Use 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.