← back

Pruning branch references in git

29 Feb, 2024

In short, to remove any unnecessary remote references, you can use the following command:

git fetch --prune

This will remove any remote references that no longer exist on the remote repository.

Pruning can avoid unwanted references from being left behind in your local repository, and it can also help to keep your repository clean and tidy.

Example:

You cloned two repos, A and B. Using repo A, you created a local feature branch, and pushed it on remote. Now, you git fetch on repo B. You get the new feature on B as well. Now, on repo A, you remove this branch and push it again. Currently, B has reference to non-existing feature branch, to solve this, do git fetch --prune (check more configs on man page - git-fetch).