Git 报错:unable to update local ref

Posted Data-Mining

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git 报错:unable to update local ref相关的知识,希望对你有一定的参考价值。

目录

问题

解决

步骤一、清除松散对象。

步骤二、刷新本地分支

步骤三、拉取远端仓库代码


问题

今天在一个老旧项目目录中同步代码时遇到了一个报错:unable to update local ref。

具体操作流程如下:

root@928c09c89c1c:/home/work/bag# git pull
error: cannot lock ref 'refs/remotes/origin/lozen/remux': 'refs/remotes/origin/lozen' exists; cannot create 'refs/remotes/origin/lozen/remux'
From git.baijiashilian.com:LLL/gloud/bag
 ! [new branch]      lozen/remux       -> origin/lozen/remux  (unable to update local ref)
error: cannot lock ref 'refs/remotes/origin/lozen/tc': 'refs/remotes/origin/lozen' exists; cannot create 'refs/remotes/origin/lozen/tc'
 ! [new branch]      lozen/tc          -> origin/lozen/tc  (unable to update local ref)
 * [new tag]         1.0.8.142-dasheng -> 1.0.8.142-dasheng
 * [new tag]         1.0.8.241         -> 1.0.8.241
 * [new tag]         1.0.9.021         -> 1.0.9.021

执行完 git pull 命令之后,最新的分支都已经同步下来,但是有两个分支报错了,具体的报错信息就是 unable to update local ref。其实这是一种比较常见的 Git 的报错,今天遇到了,就拿出来介绍一下解决方法。

解决

就像把大象装冰箱,总共分三步。

步骤一、清除松散对象。

命令如下:

git gc --prune=now

执行过程如下:

root@928c09c89c1c:/home/work/bag# git gc --prune=now
Enumerating objects: 3534, done.
Counting objects: 100% (3534/3534), done.
Delta compression using up to 64 threads
Compressing objects: 100% (1211/1211), done.
Writing objects: 100% (3534/3534), done.
Total 3534 (delta 2306), reused 3450 (delta 2230)

步骤二、刷新本地分支

同步远程仓库分支到本地,删除远程分支不存在但是本地还有的分支,执行过程如下:

root@928c09c89c1c:/home/work/bag# git remote prune origin
Pruning origin
URL: git@git.baijiashilian.com:LLL/gloud/bag.git
 * [pruned] origin/lozen

步骤三、拉取远端仓库代码

完成上面的两个步骤之后,我们就可以同步代码了,执行过程如下:

root@928c09c89c1c:/home/work/bag# git pull
remote: Enumerating objects: 123, done.
remote: Counting objects: 100% (123/123), done.
remote: Compressing objects: 100% (88/88), done.
remote: Total 123 (delta 69), reused 63 (delta 35), pack-reused 0
Receiving objects: 100% (123/123), 99.65 KiB | 2.93 MiB/s, done.
Resolving deltas: 100% (69/69), completed with 1 local object.
From git.baijiashilian.com:LLL/gloud/bag
 * [new branch]      lozen/remux -> origin/lozen/remux
 * [new branch]      lozen/tc    -> origin/lozen/tc
Already up to date.

可以看到,现在就没有问题了,已经成功把代码同步下来了,哈哈。完美!

整个问题的解决过程截图如下: 

以上是关于Git 报错:unable to update local ref的主要内容,如果未能解决你的问题,请参考以下文章

git clone报错:fatal: unable to access ‘‘: SSL certificate problem: unable to get local issuer cer

git clone报错:fatal: unable to access ‘‘: SSL certificate problem: unable to get local issuer cer

ubuntu16.04 apt-get 报错:E: Unable to locate package update(E: Unable to locate package upgrade)(没解决)(

Visual Studio 2015 NuGet Update-Package 失败/报错:Update-Package : Unable to load the service index for

Git 拉取Gitee仓库报错:“fatal: unable to access ''": Failed to connect to 127.0.0.1 port 1080:

Git报错FATAL: Unable to connect to relay host, errno=10061 kex_exchange_identificat