Next.js starter your AI actually understands. Ship internal tools in days not weeks. Pre-order $199 $499 → [Get it now]

How to prune remote branches in Git

Pruning remote branches removes references to branches that have been deleted on the remote repository but still appear in your local repository. As the creator of CoreUI with 25 years of Git experience managing hundreds of contributors, I prune remote branches regularly to keep repositories clean.

The most effective command is git fetch --prune or git remote prune origin.

Direct Answer

Use git fetch --prune to update and clean remote references in one command.

git fetch --prune

Alternative Command

Prune a specific remote without fetching:

git remote prune origin

Automatic Pruning

Configure Git to automatically prune on every fetch:

git config --global fetch.prune true

View Stale Branches

See which branches will be pruned before removing them:

git remote prune origin --dry-run

Complete Cleanup

Remove local branches that track deleted remote branches:

# List merged branches
git branch -vv | grep ': gone]' | awk '{print $1}'

# Delete them
git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -d

Explanation

When you delete a branch on GitHub or another remote, your local Git still keeps a reference to origin/branch-name. Running git fetch --prune removes these stale references, cleaning up your branch list. The --dry-run flag lets you preview what will be removed before actually deleting anything.

Best Practice Note

This is the same branch cleanup strategy we use in CoreUI’s repositories with hundreds of contributors. Regular pruning keeps your git branch -r output clean and prevents confusion about which branches actually exist on the remote. Set fetch.prune true globally to automate this maintenance.

For related Git maintenance, check out how to set upstream branch in Git and how to change remote URL in Git.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to Clone an Object in JavaScript
How to Clone an Object in JavaScript

How to capitalize the first letter in JavaScript?
How to capitalize the first letter in JavaScript?

The Best Bootstrap Alternative for Developers in 2025
The Best Bootstrap Alternative for Developers in 2025

The Wacky World of JavaScript: Unraveling the Oddities
The Wacky World of JavaScript: Unraveling the Oddities

Answers by CoreUI Core Team