如何克隆私有GitLab存储库?

问题描述 投票:23回答:4

当我这样做:

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

我收到此错误:

致命:HTTP请求失败

当我使用SSH时:

git clone username [email protected]:root/test.git

我收到此错误:

/server/user/[email protected]:root/test.git/.git/中初始化的空Git存储库 致命:'user'似乎不是git存储库 致命:远程端意外挂断

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

git github gitlab
4个回答
27
投票

你的ssh clone声明错了:git clone username [email protected]:root/test.git

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

你想省略username

git clone [email protected]:root/test.git

26
投票

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

git clone https://[email protected]/username/repository

19
投票

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

  • 使用您用于注册的电子邮件正确创建SSH密钥。我会使用默认文件名来键入Windows。别忘了介绍密码! $ ssh-keygen -t rsa -C "[email protected]" -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配置文件中的设置> SSH密钥>密钥中。
  • 获取本地连接: $ ssh -i $PWD/.ssh/id_rsa [email protected] 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.

0
投票

在做之前

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

确保在系统中添加了ssh密钥。请关注:https://gitlab.com/profile/keys

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

© www.soinside.com 2019 - 2024. All rights reserved.