无法同步远端git分支信息,提示remote ref does not exist

原创 zhaoliang  2018-05-18 22:16  阅读 856 views 次

在公司内网的github页面中直接删除了几个历史分支,回到自己的单机开发环境,git pull和git fetch之后,使用git branch -a命令查看,依然能够看到已经删除的分支,但无法checkout,使用命令git branch -d可以删除本地分支,但无法push,每次git push --delete origin时直接提示错误:

error: unable to delete 'origin/*****': remote ref does not exist

结果就是远程分支已经不存在,本地git缓存仍然显示服务器端存在已删除的分支,因为不是通过正常的git分支删除指令操作的,导致git服务器端与开发端之间的分支数据无法保持一致,又因服务器端确实删除了分支,本地缓存无法通过git pull或git fetch指令同步,结果就是上面讲的那样了。

解决方案

使用命令git fetch -p可以将最新的远端分支信息同步下来,并把远端已经不存在、但单机环境依然存在的分支信息清理掉。具体可使用git help fetch查看对应的说明

-p, --prune
           Before 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 --tags 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.

 

本文地址:http://blog.58cm.cn:8088/archives/515.html
版权声明:本文为原创文章,版权归 zhaoliang 所有,欢迎分享本文,转载请保留出处!
PREVIOUS:已经是最后一篇了
NEXT:已经是最新一篇了
相关文章 关键词:

评论已关闭!