如何将带有LFS对象的git仓库推送到gitlab

笔者最近碰到一个开源项目想学习下,按照以往的套路,先clone到本地,然后push到gitlab,结果冒出这么一个报错:

git push

Enumerating objects: 8563, done.

Counting objects: 100% (8563/8563), done.

Delta compression using up to 8 threads

Compressing objects: 100% (2614/2614), done.

Writing objects: 100% (8563/8563), 4.40 MiB | 19.35 MiB/s, done.

Total 8563 (delta 5526), reused 8563 (delta 5526)

remote: Resolving deltas: 100% (5526/5526), done.

remote: GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all".

To http://192.168.1.10:8083/xxx/xxx.git

! remote rejected main -> main (pre-receive hook declined)

error: failed to push some refs to 'http://192.168.1.10:8083/xxx/xxx.git'

用chatgpt plus + deep research试了下也没跑通,这个有时候好用,有时候不行,有点心疼每月20美金的费用值不值。

后来改用另外一个免费的AI, WOC,跑通了,可能是我之前弄来弄去搞复杂了,其实很简单,这里做下记录以备以后碰到类似的项目能节约时间。

第一步 git lfs clone

复制代码
git lfs clone https://github.com/xxx/xxx.git

第二步 git lfs fetch

复制代码
 git lfs fetch --all


会出现类似下面的消息
fetch: 5 object(s) found, done.
fetch: Fetching all references...


或者你也可以fetch指定的分支

git lfs fetch origin main

响应消息
fetch: Fetching reference refs/heads/main

第三步 确保gitlab启用LFS

复制代码
登录gitlab后台

修改文件 /etc/gitlab/gitlab.rb

设置LFS启用
gitlab_rails['lfs_enabled'] = true

重新配置GitLab
sudo gitlab-ctl reconfigure

确保要推送的gitlab仓储的LFS启用,一般默认是启用的

第四步 git remote add

复制代码
git remote add gitlab http://192.168.1.10:8083/xxx/xxx.git

第五步 git push

复制代码
git push gitlab --all

第五步 git lfs push

复制代码
git lfs push gitlab --all


会出现类似下面的消息

Locking support detected on remote "gitlab". Consider enabling it with:
  $ git config lfs.http://192.168.1.10:8083/xxx/xxx.git/info/lfs.locksverify true
Uploading LFS objects: 100% (5/5), 130 MB | 0 B/s, done.

搞定!

相关推荐
是宇写的啊8 小时前
Git远程操作
git
our_times16 小时前
# Git 高频命令实战指南:从日常开发到进阶协作
git
PBitW17 小时前
git 中容易遗忘的点 (二) ⚡⚡⚡
前端·git·面试
PBitW17 小时前
git 中容易遗忘的点 (三) 🚀🚀🚀
前端·git·面试
酿情师20 小时前
Gitlab 任意文件读取漏洞(CVE-2016-9086)
gitlab
郑州光合科技余经理20 小时前
家政预约小程序后端源码深度剖析:支付回调实战
java·开发语言·前端·git·小程序·架构·php
北极糊的狐21 小时前
钉钉小程序 Git 版本管理完整流程
git·小程序·钉钉
Fzuim1 天前
当 AI 也成为提交者:ThinkFlow 的 Git 提交规范,是怎么定的
git·agent·thinkflow
CodexDave2 天前
数据库连接池耗尽:排查顺序与三层兜底
服务器·前端·数据库·git·云原生·容器·kubernetes
糖果罐子♡2 天前
TortoiseGit 首次上传本地工程至已初始化的GitLab仓库教程
gitlab