You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git LFS强制使用HTTPS而非SSH的问题排查求助

强制Git LFS使用SSH替代HTTPS的解决步骤

1. 清理冲突的本地配置

首先移除可能导致HTTPS端点被优先选择的冲突配置:

  • 打开本地仓库的.git/config,删除以下条目:
    [lfs "https://git.myurl.de/mnt/raid/git-repos/reponame.git/info/lfs"]
        access = ssh
    
  • 编辑.lfsconfig,将access = basic改为access = ssh,确保配置统一:
    [lfs]
        url = ssh://git@git.myurl.de:22/mnt/raid/git-repos/reponame.git/info/lfs
    [lfs "ssh://git@git.myurl.de:22/mnt/raid/git-repos/reponame.git"]
        access = ssh
    

2. 强制设置LFS SSH端点优先级

通过命令行直接覆盖本地LFS配置,确保SSH端点被强制使用:

# 针对当前仓库设置LFS URL(优先级最高)
git config --local lfs.url ssh://git@git.myurl.de:22/mnt/raid/git-repos/reponame.git/info/lfs

# 强制SSH访问方式
git config --local lfs.ssh.access ssh
git config --local lfs.ssh.variant simple

3. 禁用HTTPS端点

直接禁用问题中的HTTPS端点,阻止Git LFS尝试使用它:

git config --local lfs.https://git.myurl.de/mnt/raid/git-repos/reponame.git/info/lfs.enabled false

4. 修复服务器端路径与依赖问题

针对服务器端的路径拼接错误和git-lfs-transfer缺失问题:

  • 确保服务器上的git-lfs-transfer命令存在于git用户的PATH中(通常在/usr/bin/或/usr/local/bin/),若重装后仍不存在,重新编译安装Git LFS:
    sudo apt remove git-lfs
    curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
    sudo apt install git-lfs
    git lfs install --system
    
  • 检查服务器仓库的LFS配置,确保路径正确:
    cd /mnt/raid/git-repos/reponame.git
    git config lfs.url ssh://git@git.myurl.de:22/mnt/raid/git-repos/reponame.git/info/lfs
    

5. 重置Git LFS钩子与缓存

清理本地钩子和缓存,确保配置生效:

# 卸载并重新安装LFS钩子
git lfs uninstall
git lfs install --force

# 清理LFS缓存并重新拉取
git lfs prune
git lfs fetch origin

6. 验证配置与测试推送

执行以下命令验证LFS环境:

git lfs env

确认输出中的Endpoint已变为SSH地址,而非HTTPS。随后测试推送:

GIT_TRACE=1 git lfs push origin <你的分支名>

查看日志确认所有LFS操作均通过SSH协议进行。


内容的提问来源于stack exchange,提问作者Timmytomate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 13:29:52