Why do I see a deleted remote branch?

会有一股神秘感。 提交于 2019-12-08 15:04:24

问题


I have a remote repository and 2 clones.
I create a branch in one of the clones e.g. test. I do some work and 2 commits. I merge to master branch and push -u the branch.
I do a git pull in the other clone.
I see both master and test.
In the first clone project I do:
git origin :test to delete test branch on remote repository.
test is deleted on remote repos.
I do git branch -D test and the test branch is deleted locally as well.
If I do git branch -a I get:

*master  
remotes/origin/master    

Now in the second repository I do a git pull.
On the pull the local test seems to be deleted but git seems to "think" that the remote test branch still exist.
If I do git branch -a I get:

* master  
  remotes/origin/HEAD -> origin/master  
  remotes/origin/master  
  remotes/origin/test    

Why does the deleted test branch appear as a remote branch?


回答1:


The default options for git fetch (and consequently git pull) do not prune deleted remote branches. I'm not sure what the logic behind this default is. In any case, to prune deleted remote branches, either fetch with

git fetch -p

or run

git remote prune [-n] <name>

explicitly. With the -n flag, it will report which branches will be pruned, but not actually prune them. See git-fetch(1) and git-remote(1) for more information.




回答2:


Try using this command git remote prune origin. The deleted branch should disappear. This should remove local references to remote branches.



来源:https://stackoverflow.com/questions/17128466/why-do-i-see-a-deleted-remote-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!