git - 远程分支 "apparently" 未删除

git - remote branch "apparently" not deleted

开发者A创建远程分支

git checkout -b myBranch
git push -u origin myBranch

开发者B查看

git fetch origin myBranch
git checkout myBranch

他们都做了一些工作,commit,pull 等。当他们完成后,合并回 develop

git checkout develop
git merge --no-ff myBranch
git push origin develop

并删除分支

# Developer A
git branch -d myBranch             # delete local branch
git push origin --delete myBranch  # delete remote branch

# Developer B
git branch -d myBranch
git fetch

此时只有推送远程删除的开发者A才能看到远程的正确状态。开发人员 B 仍然在远程看到 myBranch,即使它不再存在。如果开发人员 B 尝试检查 myBranch 并拉取,则会收到 'cannot find myBranch ref' 错误。

#Developer A
git branch -a
  * develop
  remotes/origin/HEAD -> origin/develop
  remotes/origin/develop
  remotes/origin/production

#Developer B
git branch -a
  * develop
  remotes/origin/myBranch                 # <<<<< why is this line here??
  remotes/origin/HEAD -> origin/develop
  remotes/origin/develop
  remotes/origin/production

如果我们继续 bitBucket web 控制台并查看 repo,分支 'myBranch' 不存在。

这是怎么回事,为什么,我们该如何解决?

开发者 B 需要在 git fetch 上使用 -p 参数。 git fetch -p 此参数将删除远程上不存在的所有引用。

git branch -a

-a代表所有分支(本地+远程)这就是用户看到所有分支的原因。

Developer B still sees that myBranch on remote, even though it no longer exists

你应该执行:git fetch --all --prune
修剪将删除您的分支的所有本地副本,从服务器中删除的标签。


您可以将修剪值设置为默认值,这样它会在每次提取时删除已删除的分支和标签

git config fetch.prune true

-p / --prune

After fetching, remove any remote-tracking references that no longer exist on the remote.

Tags are not subject to pruning if they are fetched only because of the default tag auto-following or due to a --tag option.

However, if tags are fetched due to an explicit refspec (either on the command line or in the remote configuration, for example if the remote was cloned with the --mirror option), then they are also subject to pruning.