如何克隆私有GitLab存储库?

max*_*oku 31 git github gitlab

当我这样做:

git clone https://example.com/root/test.git
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

致命:HTTP请求失败

当我使用SSH时:

git clone username git@example.com:root/test.git
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

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

它是一个私有存储库,我添加了SSH密钥.

DrC*_*ord 29

你的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
Run Code Online (Sandbox Code Playgroud)

  • 这是我尝试的第一件事。它询问git@example.com的密码,然后由于我不是管理员而拒绝了密码(我猜是吗?) (2认同)
  • 当然。我仅使用example.com来掩盖我的身份。 (2认同)

gar*_*ryp 29

如果您正在使用GitHub尝试此操作,则可以使用您输入的SSH执行此操作:

git clone https://username@github.com/username/repository
Run Code Online (Sandbox Code Playgroud)

  • 询问是关于gitlab (2认同)

Uli*_*uri 24

对于GitLab,基于HTTPS的克隆似乎没有直接的解决方案.因此,如果您需要基于SSH的克隆,则应考虑以下三个步骤:

  • 使用您用于注册的电子邮件正确创建SSH密钥.我会使用默认文件名来键入Windows.别忘了介绍密码!

    $ 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.
    
    Run Code Online (Sandbox Code Playgroud)
  • 将最近id_rsa.pub生成的所有内容复制并粘贴到GitLab配置文件中的设置> SSH密钥>密钥中.

  • 获取本地连接:

    $ 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.
    
    Run Code Online (Sandbox Code Playgroud)

最后,克隆任何私有或内部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.
Run Code Online (Sandbox Code Playgroud)

  • 这对我有用,希望我必须通过 ssh 而不是 https 进行克隆作为最后一步,将地址中的“https://”更改为“git@”。 (2认同)

小智 7

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

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