Alberto
Alberto

Reputation: 12899

Git branch shows deleted remote branch

If I check the list of the branches on my remote repository, I see only the ones that are supposed to exist, but if I check locally using:

git branch -a

I still see the ones deleted using the delete this branch feature that Github propose after merging a Pull Request

How can I "hide/ delete" this branches from git branch -a?

Upvotes: 10

Views: 6474

Answers (2)

Subrato Pattanaik
Subrato Pattanaik

Reputation: 6049

I am adding this answer just to add one point to @bk2204 answer.

If one or more of the branches in the remote is deleted and you don't want to see the remote deleted branches in your local repository then you can use the below git command for only removing the deleted remote branches.

git remote prune

This will only give you the information about the remote branches which is deleted and removes the same branches from the local.

The command git fetch --prune or git fetch -p fetches the remote current state first and the deletes the refs to branches in local that doesn' exist in the remote.

I can say that git fetch --prune is more likely a combination of git fetch and git remote prune. Note that git fetches the remote state first before pruning.

Now, you have option choose either of them according to the requirements or demands. 🎉✨

Upvotes: 2

bk2204
bk2204

Reputation: 76409

You can use the --prune option to git fetch. If your remote is origin, that would look like git fetch --prune origin.

Note that this will perform a regular fetch as well.

If you want to set this automatically, you can run git config remote.origin.prune true, which will cause future fetches and pulls to automatically prune deleted remote branches.

Upvotes: 28

Related Questions