简体   繁体   中英

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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM