【问题标题】:How can I clone a private GitLab repository?如何克隆私有 GitLab 存储库?
【发布时间】:2015-07-24 00:31:22
【问题描述】:

当我这样做时:

git clone https://example.com/root/test.git

我收到此错误:

致命:HTTP 请求失败

当我使用 SSH 时:

git clone username git@example.com:root/test.git

我收到此错误:

在 /server/user/git@example.com:root/test.git/.git/ 中初始化空的 Git 存储库
致命:“用户”似乎不是 git 存储库
致命:远端意外挂断

这是一个私有存储库,我已经添加了我的 SSH 密钥。

【问题讨论】:

  • 您将不得不向我们提供更多信息或阅读 git clone 文档并关注它们...git clone:git-scm.com/docs/git-clone 或告诉我们您尝试克隆的实际名称.. .
  • This 解释了为什么在您的项目是私有的情况下只复制项目主页中的链接是错误的。

标签: git github gitlab


【解决方案1】:

对于 GitLab 的基于 HTTPS 的克隆,似乎没有直接的解决方案。因此,如果您想要基于 SSH 的克隆,您应该考虑以下三个即将执行的步骤:

  • 使用您用于注册的电子邮件正确创建 SSH 密钥。我会使用默认文件名作为 Windows 的密钥。不要忘记输入密码! (提示:如果您在这里已经有一个 ssh 密钥,则可以跳过此步骤

     $ ssh-keygen -t rsa -C "your.email@example.com" -b 4096
    
     Generating public/private rsa key pair.
     Enter file in which to save the key ($PWD/.ssh/id_rsa): [\n]
     Enter passphrase (empty for no passphrase):[your password]
     Enter same passphrase again: [your password]
     Your identification has been saved in $PWD/.ssh/id_rsa.
     Your public key has been saved in $PWD/.ssh/id_rsa.pub.
    
  • 将最近生成的 id_rsa.pub 中的所有内容复制并粘贴到 GitLab 配置文件中的 Setting>SSH 密钥>Key 中。

     # Copy to clipboard
     pbcopy < ~/.ssh/id_rsa.pub
    
  • 本地连接:

     $ ssh -i $PWD/.ssh/id_rsa git@gitlab.com
    
     Enter passphrase for key "$PWD/.ssh/id_rsa": [your password]
     PTY allocation request failed on channel 0
     Welcome to GitLab, you!
     Connection to gitlab.com closed.
    

最后,克隆任何私有或内部 GitLab 存储库!

$ git clone https://git.metabarcoding.org/obitools/ROBIBarcodes.git

Cloning into 'ROBIBarcodes'...
remote: Counting objects: 69, done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 69 (delta 14), reused 0 (delta 0)
Unpacking objects: 100% (69/69), done.

【讨论】:

  • 这对我有用,希望我必须通过 ssh 而不是 https 作为最后一步进行克隆,将地址中的“https://”更改为“git@”。
  • 我必须使用ssh -i ~/.ssh/id_ed25519 myusername@git.mysuborga.myorga.com(或使用“$PWD”而不是“~”),因为我只将我的公钥添加到 GitLab 中所选子组织的帐户中,不是 到整个 GitLab。我什至没有使用相同用户名的通用 GitLab 用户帐户。而“ed25519”是当今ssh密钥对的标准。我不得不将ssh-keyscan myusername@git.mysuborga.myorga.com 的输出添加到~/.ssh/known_hosts 以抑制警告The authenticity of host [xyz] can't be established.
【解决方案2】:

你的 ssh clone 声明错误:git clone username git@example.com:root/test.git

该语句将尝试将名为 username 的存储库克隆到相对于您当前路径 git@example.com:root/test.git 的位置。

你想省略username:

git clone git@example.com:root/test.git

【讨论】:

  • 这是我尝试的第一件事。它询问 git@example.com 的密码,然后拒绝密码,因为我不是管理员(我猜?)
  • 当然。我只是使用 example.com 来混淆我的身份。
  • 你的用户名是git吗?
  • @maximusdooku 您可能需要将您的私钥放在路径中。
  • 这个答案是为那些使用用户名和密码的人准备的。如果您想使用您的私有 SSH 密钥(之前已将公钥添加到您的私有 GitLab 项目中),请参阅@UlisesRosas-Puchuri 的答案:您需要将您的私有密钥ssh -i 用于私有 gitlab 项目,以便在克隆项目之前,两者都相互认识。
【解决方案3】:

如果您在 GitHub 上尝试此操作,您可以输入 SSH 来执行此操作:

git clone https://username@github.com/username/repository

【讨论】:

  • 嗨,我继续收到此错误:致命:HTTP 请求失败
  • 地址一定有问题。你得到的错误是告诉你找不到 repo,我认为你的凭据是好的。如果可能的话,您可以发布您正在使用的确切命令(如果您不想共享,可以重命名 repo)。
  • 把https前缀放入,取出test.git部分。确保您的仓​​库名称是地址的最后一部分。例如:git clone https://serverusername@github.com/serverusername/myrepo
  • 这个questin是关于gitlab的
【解决方案4】:

我尝试了所有这些建议。这是最终对我有用的方法:

  1. https://gitlab.com/-/profile/personal_access_tokens 创建访问令牌。 注意:请务必复制令牌并保存。您将需要它!
  2. git clone https://gitlab.com/USERNAME/REPO.git(将 USERNAME 和 REPO 替换为您的唯一信息)。
  3. 在请求时输入您的 GitLab 用户名。
  4. 当它询问您的密码时,请输入您在步骤 1 中创建的访问令牌。您的 GitLab 帐户密码对此不起作用。访问令牌就是您想要的。

【讨论】:

    【解决方案5】:

    做之前

    git clone https://example.com/root/test.git
    

    确保您已在系统中添加 ssh 密钥。关注这个:https://gitlab.com/profile/keys

    添加后运行上述命令。它将提示您输入 gitlab 用户名和密码,并且在身份验证时,它将被克隆。

    【讨论】:

    • 很好的提示。我在导航到 ~/.ssh 后使用了命令 ssh-add id_rsa 然后我的克隆命令起作用了。
    【解决方案6】:

    您可能需要~/.ssh/config

    Host gitlab.YOURDOMAIN.DOMAIN
        Port 1111
        IdentityFile ~/.ssh/id_rsa
    

    然后你可以使用git clone git@DOMAINandREPOSITORY。这意味着您始终使用用户 git

    【讨论】:

      【解决方案7】:

      如果您使用的是 Windows,

      1. 创建一个文件夹并从那里打开 git bash

      2. 在 git bash 中,

        git clone git@gitlab.com:Example/projectName.git

      【讨论】:

        猜你喜欢
        • 2014-10-30
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        • 2017-03-04
        • 1970-01-01
        • 2019-12-02
        • 1970-01-01
        • 2021-02-04
        相关资源
        最近更新 更多