Scroll Top

Pruning stale GIT branches

Share this

If you’ve been working on a repo for awhile, you’ve probably accumulated a fair amount of local branches that no longer exist on the remote (e.g., github). You’ll want to occasionally clean those up; fortunately git has a command for that: git prune.

Here’s how:

Open a command window and navigate to your working folder. Get a list of all stale branches that no longer exist on the remote by doing a dry run:

git remote prune origin --dry-run 

If that list looks good (hint: it should unless you really like keeping branches around), go ahead and prune them:

git remote prune origin 

Note that this will only delete branches that have been merged so any unmerged branches or those never pushed will not be deleted.

Share this

Related Posts

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.