Git Prune Remote Branches That No Longer Exist

In git, you’re working with branches. A branch describes a parallel state to the main branch. You can change the code in your branch and test it without affecting the stable main branch.

In your development team, you’ll review and work on different features which probably have their own branch. After a while, you’ll have different tracking for remote branches. Over time, there’s a chance that these remote branches no longer exist. Thankfully, the git command line lets you clear references to previously deleted remote branches.

git Series Overview

Git keeps your local data until you’re explicitly throwing it away. This will also keep references to remote branches, even if they no longer exist.

You can delete the tracking of remote references by adding the --prune flag while fetching:

git fetch --prune

# or with a shortcode 
git fetch -p  

You may also delete the remote reference without fetching:

git remote prune <branch-name>  

That’s it!


Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.