git 如何克隆私有 GitLab 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30202642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I clone a private GitLab repository?
提问by maximusdooku
When I do this:
当我这样做时:
git clone https://example.com/root/test.git
I am getting this error:
我收到此错误:
fatal: HTTP request failed
致命:HTTP 请求失败
When I use SSH:
当我使用 SSH 时:
git clone username [email protected]:root/test.git
I am getting this error:
我收到此错误:
Initialized empty Git repository in /server/user/[email protected]:root/test.git/.git/
fatal: 'user' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
在 /server/user/[email protected]:root/test.git/.git/ 中初始化空的 Git 仓库
致命:'user' 似乎不是一个 git 仓库
致命:远程端意外挂断
It's a private repository, and I have added my SSH keys.
这是一个私有存储库,我已经添加了我的 SSH 密钥。
采纳答案by DrCord
You have your ssh clone
statement wrong: git clone username [email protected]:root/test.git
您的 sshclone
语句有误:git clone username [email protected]:root/test.git
That statement would try to clone a repository named username
into the location relative to your current path, [email protected]:root/test.git
.
该语句将尝试克隆一个命名username
为相对于您当前路径的位置的存储库,[email protected]:root/test.git
.
You want to leave out username
:
你想省略username
:
git clone [email protected]:root/test.git
回答by garryp
If you're trying this with GitHub, you can do this with your SSH entered:
如果您在 GitHub 上尝试此操作,则可以在输入 SSH 的情况下执行此操作:
git clone https://[email protected]/username/repository
回答by Ulises Rosas-Puchuri
It looks like there's not a straightforward solution for HTTPS-based cloning regarding GitLab. Therefore if you want a SSH-based cloning, you should take account these three forthcoming steps:
对于 GitLab 的基于 HTTPS 的克隆,似乎没有一个简单的解决方案。因此,如果您想要基于 SSH 的克隆,您应该考虑接下来的三个步骤:
Create properly an SSH key using your email used to sign up. I would use the default filename to key for Windows. Don't forget to introduce a password!
$ 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.
Copy and paste all content from the recently
id_rsa.pub
generated into Setting>SSH keys>Keyfrom your GitLab profile.Get locally connected:
$ 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.
使用您用于注册的电子邮件正确创建 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.
Finally, clone any private or internal GitLab repository!
最后,克隆任何私有或内部 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.
回答by Amar Nath Boral
Before doing
做之前
git clone https://example.com/root/test.git
make sure that you have added ssh key in your system. Follow this : https://gitlab.com/profile/keys.
确保您已在系统中添加了 ssh 密钥。按照这个:https://gitlab.com/profile/keys。
Once added run the above command. It will prompt for your gitlab username and password and on authentication, it will be cloned.
添加后运行上面的命令。它将提示您输入 gitlab 用户名和密码,并在身份验证时进行克隆。
回答by Ben
You might need a ~/.ssh/config
:
您可能需要一个~/.ssh/config
:
Host gitlab.YOURDOMAIN.DOMAIN
Port 1111
IdentityFile ~/.ssh/id_rsa
and then you can use git clone git@DOMAINandREPOSITORY
. This means you always use the user git
.
然后你可以使用git clone git@DOMAINandREPOSITORY
. 这意味着您始终使用 user git
。