简体   繁体   中英

Why does Git checkout this deleted branch without complaining?

I just removed a remote branch from our distant Git repository:

$ git push origin :obsoleteBranch

To git@<path_to_our_git_repo>/our_git_repo.git
 - [deleted]         obsoleteBranch

Now my local copy of obsoleteBranch is now tracking a branch that is "gone":

git branch -avv
* obsoleteBranch  dbef4b0 [origin/obsoleteBranch: gone] commit log...

So far, so good!

The problem is my colleague still sees the remote branch, even after git fetch --all :

$ git fetch --all
Fetching origin
......
$ git branch -avv
......
remotes/origin/obsoleteBranch dbef4b0 commit log...
......

Git doesn't complain when my colleague tries to checkout the removed branch!

$ git checkout --track origin/obsoleteBranch

and actually does the checkout just where the removed branch used to be!

But (proof that the remote branch is actually gone) my colleague cannot delete it:

$ git push origin :obsoleteBranch
error: unable to delete 'obsoleteBranch': remote ref does not exist
error: failed to push some refs to 'git@<path...>/our_git_repo.git'

What is going wrong?

Didn't git fetch --all completely synchronize my colleague's repository with the remote repository?

What command should he run, then, in order to have his local repository take into account the branch deletion for git branch -avv and git checkout ?

git caches info about remote branches. Your colleague must have fetched info about that obsoleteBranch before. That's why he sees it and is able to check out the commit (the commit is also downloaded to his local repo).

git fetch --all --prune

should remove now-orphaned references to remote branches.

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