如何克隆私有GitLab存储库?

如何克隆私有GitLab存储库?,git,github,gitlab,Git,Github,Gitlab,当我这样做时: git clone https://example.com/root/test.git 我得到这个错误: 致命:HTTP请求失败 当我使用SSH时: git clone username git@example.com:root/test.git 我得到这个错误: 已在/server/user中初始化空Git存储库/git@example.com:root/test.git/.git/ 致命:“用户”似乎不是git存储库 致命:远程端意外挂起 这是一个私有存储库,我添加了我的

当我这样做时:

git clone https://example.com/root/test.git
我得到这个错误:

致命:HTTP请求失败

当我使用SSH时:

git clone username git@example.com:root/test.git
我得到这个错误:

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


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

您的SSH
clone
语句错误:
git clone用户名git@example.com:root/test.git

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

您想省略
用户名

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

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

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

关于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.
    
  • 将最近生成的
    id\u rsa.pub
    中的所有内容复制并粘贴到GitLab配置文件中的Setting>SSH keys>Key

  • 获取本地连接:

    $ 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.
做之前

git clone https://example.com/root/test.git
确保已在系统中添加ssh密钥。请遵循以下步骤:


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

您可能需要一个
~/.ssh/config

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

然后您可以使用git clonegit@DOMAINandREPOSITORY。这意味着您在使用Windows时始终使用用户
git

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

  • 在git狂欢中

    git克隆git@gitlab.com:Example/projectName.git


  • 您好,我继续得到这个错误:致命:HTTP请求失败必须是地址有问题。您得到的错误是告诉您无法找到回购协议,我认为您的凭据没有问题。如果可能的话,您可以发布您正在使用的确切命令(如果您不想共享,可以重命名repo)。我已经尝试了两种方法:a)git clone b)git clone插入https前缀并取出test.git部分。确保您的回购协议名称是地址的最后一部分。例如:
    git克隆https://serverusername@github.com/serverusername/myrepo
    这个问题是关于Gitlab的这是我第一次尝试的。它要求输入密码git@example.com然后拒绝密码,因为我不是管理员(我猜是吧?)。我只是用example.com来混淆我的身份。你的用户名是不是
    git
    ?@maximudooku你可能需要把你的私钥放在路径中。这个答案是给那些使用用户名和密码的人的。如果您想使用您的私有SSH密钥(之前将公钥添加到您的私有GitLab项目中),请参阅@ulisesrossas Puchuri的答案:您需要
    ssh-i
    您的私有gitlab项目的私钥,以便在克隆项目之前彼此了解。您必须向我们提供更多信息或阅读git clone文档并遵循它们…git clone:或告诉我们您试图克隆的内容的实际名称。。。解释了为什么当你的项目是私人项目时,仅仅复制项目主页中的链接是错误的。非常好的提示。导航到~/.ssh后,我使用了命令
    ssh add id_rsa
    。然后我的clone命令工作了。这对我来说很有效,希望我必须通过ssh而不是https进行克隆作为最后一步,将地址中的“https://”更改为“git@”。我必须使用
    ssh-I~/.ssh/id_ed25519myusername@git.mysuborga.myorga.com
    (或使用“$PWD”而不是“~”),因为我只将公钥添加到GitLab中所选的子组织的帐户,而不是整个GitLab。我甚至没有使用相同用户名的通用GitLab用户帐户。而“ed25519”是目前ssh密钥对的标准。我必须添加ssh keyscan的输出myusername@git.mysuborga.myorga.com到
    ~/.ssh/known_hosts
    以抑制警告
    无法建立主机[xyz]的真实性。