git报错系列---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)
解决方案:
1、清除松散对象
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)
2、刷新本地分支
同步远程仓库分支到本地,删除远程分支不存在但是本地还有的分支,执行过程如下:
root@928c09c89c1c:/home/work/bag# git remote prune origin Pruning origin URL: git@git.baijiashilian.com:LLL/gloud/bag.git * [pruned] origin/lozen
3、拉取远端仓库代码
完成上面的两个步骤之后,我们就可以同步代码了,执行过程如下:
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.