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

通过SSH配置Host访问Gitea仓库提示“不是Git仓库”的解决方法

可行解决方案
  • 改用SSH协议完整格式访问
    用ssh://格式替代简写的host:path格式,避免Git自动给仓库路径加前缀斜杠,命令如下:

    git ls-remote ssh://myserver/user1/repo1.git
    

    因为你的SSH Config已经指定了User git,这个命令会自动用git用户登录,不用额外写用户名。

  • 给SSH Config加IdentitiesOnly yes
    在~/.ssh/config的myserver条目里添上这一行,强制SSH只使用你指定的密钥,避免密钥冲突导致Gitea认不出身份:

    Host myserver
      HostName 172.2.1.1
      User git
      Port 22
      IdentityFile ~/.ssh/id_ed25519_repo1
      IdentitiesOnly yes
    

    改完再跑原来的命令试试:

    git ls-remote myserver:user1/repo1.git
    
  • 强制Git用指定的SSH Config
    有些旧版本Git可能会用系统默认SSH配置干扰你的自定义规则,执行下面的命令把Git全局配置改成强制用你的SSH Config:

    git config --global core.sshCommand "ssh -F ~/.ssh/config"
    
  • 给单个仓库做SSH别名映射(进阶)
    如果前面的方法都没用,你可以给这个仓库单独建个SSH Host条目,直接把仓库路径嵌进去:

    Host repo1
      HostName 172.2.1.1
      User git
      Port 22
      IdentityFile ~/.ssh/id_ed25519_repo1
      RemoteCommand git-upload-pack 'user1/repo1.git'
    

    之后直接用这个别名访问就行:

    git ls-remote repo1
    
  • 先手动验证SSH会话里的仓库权限
    先SSH登到服务器上,手动跑Git命令确认仓库能访问:

    ssh myserver
    # 登录成功后执行
    git-upload-pack 'user1/repo1.git'
    

    如果这个命令能返回仓库的分支、标签信息,说明Gitea那边权限和仓库都没问题,问题就出在Git客户端的参数传递上;要是报错,就得去Gitea网页端检查仓库权限或者路径拼写了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 04:08:22