git 克隆一个私有的 Github 仓库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2505096/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:06:27  来源:igfitidea点击:

Cloning a private Github repo

gitgithubprivate

提问by Solomon

I have a private repository on Github for a project I'm working on. Until now I had only worked on my home desktop, but I just bought a laptop, and am trying to set it up so that I can work on the project from either computer, and push / pull changes.

我在 Github 上有一个用于我正在处理的项目的私有存储库。到目前为止,我只在家用台式机上工作过,但我刚买了一台笔记本电脑,我正在尝试对其进行设置,以便我可以从任何一台计算机上处​​理项目,并推送/拉取更改。

I added a new SSH key to my Github account for the laptop, and was successful in cloning and making changes to a public test repo that I set up. However, I couldn't clone the private repo. Is there anything special I need to do in the command line in order to clone a private repo? Do I need to set up a new GitHub account for my laptop and set myself up as a collaborator?

我在笔记本电脑的 Github 帐户中添加了一个新的 SSH 密钥,并成功克隆并更改了我设置的公共测试存储库。但是,我无法克隆私人回购。为了克隆私有仓库,我需要在命令行中做什么特别的事情吗?我是否需要为我的笔记本电脑设置一个新的 GitHub 帐户并将自己设置为协作者?

The command I used was git clone git://github.com/myusername/reponame.git

我使用的命令是 git clone git://github.com/myusername/reponame.git

采纳答案by mac

Private clone URLs take the form [email protected]:username/repo.git- perhaps you needed to use git@rather than git://?

私有克隆 URL 采用以下形式[email protected]:username/repo.git- 也许您需要使用git@而不是git://?

git://URLs are read only, and it looks like private repos do not allow this form of access.

git://URL 是只读的,看起来私有存储库不允许这种形式的访问。

回答by charlchad

This worked for me:

这对我有用:

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

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

This, of course, was after adding my SSH key to Github. I used this on a CentOs server, if that's necessary.

当然,这是在将我的 SSH 密钥添加到 Github 之后。如果有必要,我在 CentOs 服务器上使用了它。

回答by izik f

This worked for me:

这对我有用:

git clone https://username:[email protected]/username/repo_name.git

回答by lzl124631x

I have met this issue several times and every time I landed on this page, tried every thing and failed!

我已经多次遇到这个问题,每次我登陆这个页面,尝试每件事都失败了!

It's because I have 2FA enabled!!!

这是因为我启用了 2FA !!!

According to https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled

根据https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled

If you have enabled?two-factor authentication, or if you are accessing an organization that uses?SAML single sign-on, you must?provide a personal access token?instead of entering your password for HTTPS Git.

如果你启用了?两因素身份验证,或者如果您正在访问使用的组织?SAML 单点登录,您必须吗?提供个人访问令牌?而不是输入您的 HTTPS Git 密码。

  1. Follow this linkand create an access token
  2. git clone https://github.com/username/repo_name.git(The default git repo link is good enough!)
  3. Enter your username and use the access token as password!!
  1. 按照此链接创建访问令牌
  2. git clone https://github.com/username/repo_name.git(默认的 git repo 链接就足够了!)
  3. 输入您的用户名并使用访问令牌作为密码!!


Update:

更新:

  • If you don't mind exposing your access token in the command line, you can also paste the access token as username then hit enter enter (no need for password).
  • Hate copy&pasting the access token over and over again?
    Use git config credential.helper store(don't do this on machine you don't trust)
  • 如果您不介意在命令行中公开您的访问令牌,您也可以将访问令牌粘贴为用户名,然后按回车键(不需要密码)。
  • 讨厌一遍又一遍地复制和粘贴访问令牌?
    使用git config credential.helper store(不要在你不信任的机器上这样做)

回答by Black Mamba

For me the solution was:

对我来说,解决方案是:

git clone https://[email protected]

Here you need to be the owner of the repo but if you aren't then it will go as

在这里,您需要成为 repo 的所有者,但如果不是,则它将作为

git clone https://[email protected]/ownersusername/repo_name.git

If you have 2FA enabledthen:

如果你有2FA enabled那么:

  1. Go to the settings from the profile icon in top right or visit https://github.com/settings/profile
  2. Go to the bottom tab or go to https://github.com/settings/tokens
  3. Open last tab here Personal tokens. And generate a token
  4. Copy the token and run git clone https://[email protected]
  1. 从右上角的个人资料图标转到设置或访问https://github.com/settings/profile
  2. 转到底部选项卡或转到https://github.com/settings/tokens
  3. 在此处打开最后一个选项卡个人令牌。并生成令牌
  4. 复制令牌并运行 git clone https://[email protected]

When prompted for password put that token in here. Token generation image here

当提示输入密码时,把那个令牌放在这里。 令牌生成图像在这里

回答by Gustavo Coelho

Using Git for Windows it is easier to use HTTPS url.

使用 Git for Windows 更容易使用 HTTPS url。

Open a git shell then git clone https://github.com/user/repo. Enter username and password when prompted. No need to setup a SSH key.

然后打开一个 git shell git clone https://github.com/user/repo。出现提示时输入用户名和密码。无需设置 SSH 密钥。

回答by oneworld

I have a company (private) account and 2-Factor-Authentication enabled, so I had to combine a few posts to make it work as below. (Jotting down so it may be useful to someone with the same situation)

我有一个公司(私人)帐户并启用了 2-Factor-Authentication,所以我必须结合一些帖子才能使其工作如下。(记下来,可能对有同样情况的人有用)

Initially it was the Fatal Error. 
fatal: repository 'https:
...
remote: Repository not found.
fatal: repository 'https:

Installed the credential manager and updated GIT as mentioned here: https://codeshare.co.uk/blog/how-to-solve-the-github-error-fatal-httprequestexception-encountered/

安装凭据管理器并更新 GIT,如下所述:https: //codeshare.co.uk/blog/how-to-solve-the-github-error-fatal-httprequestexception-encountered/

That did not solve the problem as the issue moved to the below when I tried using the clone command as follows:

这并没有解决问题,因为当我尝试使用 clone 命令时,问题转移到了下面,如下所示:

$ git clone https://<username>:<password>@github.com/<ORG_NAME>/<PROJECT-NAME>.git

remote: Invalid username or password.
fatal: Authentication failed for 'https://

My password had $ symbol in itand for some reason GIT command line / GIT Bash did not like it. I can see this on the error returned text did not have the $ symbol in it.

我的密码中有 $ 符号,出于某种原因,GIT 命令行 / GIT Bash 不喜欢它。我可以在错误返回的文本中看到这一点,其中没有 $ 符号。

fatal: Authentication failed for 'https://<username>:<password-missing-$-symbol>@github.com/<ORG_NAME>/<PROJECT-NAME>.git'

I had to reference this site: https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage

我不得不参考这个网站:https: //git-scm.com/book/en/v2/Git-Tools-Credential-Storage

Please note: If an incorrect password is stored for your account in Windows Credential Managerit will also add to the problem. I removed the github credential stored this way before moving to the step below.

请注意:如果在Windows 凭据管理器中为您的帐户存储了不正确的密码, 它也会加剧问题。在转到下面的步骤之前,我删除了以这种方式存储的 github 凭据。

$ git config --global credential.helper cache
$ git clone https://<username>:<password>@github.com/<ORG_NAME>/<PROJECT-NAME>.git

Now the Windows Credential manager popped-up. I typed my username and password in the text-boxes (This accepted my password that had the $ symbol) and prompted me for a 2-Factor Authentication code. I typed in the authentication code from Google Authenticator, and the clone started perfectly.

现在 Windows 凭据管理器弹出。我在文本框中输入了我的用户名和密码(这接受了我带有 $ 符号的密码)并提示我输入 2-Factor Authentication 代码。我输入了来自 Google Authenticator 的身份验证代码,克隆完美启动。

回答by ireshika piyumalie

When cloning from private repos with 2FA enable, there is a simple steps which you need to follow

从启用 2FA 的私有存储库克隆时,您需要遵循一个简单的步骤

  1. Go to your Git account
  2. Go to Settings-> Developer Settings->Personal Access Token
  3. Click on Generate new token
  4. Create a token with title you want and with the functionalities
  5. When you are cloning the private repo, by using git clone repoName, after entering your user name, give personal access token as the password.
  1. 转到您的 Git 帐户
  2. 转到设置-> 开发者设置-> 个人访问令牌
  3. 单击生成新令牌
  4. 创建一个带有您想要的标题和功能的令牌
  5. 克隆私有仓库时,使用 git clone repoName,输入用户名后,提供个人访问令牌作为密码。

Follow same steps when you get Authentication failed error message for Private repo

当您收到 Private repo 的 Authentication failed 错误消息时,请按照相同的步骤操作

回答by MK Yung

In response to mac's answer, you can get your SSH clone URL on your github repo page, by clicking SSHon You can clone with HTTPS, SSH, or Subversion.and copy the URL.

为了响应Mac的答案,你可以得到你的SSH克隆网址,您的GitHub库页面,通过点击SSHYou can clone with HTTPS, SSH, or Subversion.再复制网址。

回答by Usman Hussain

This worked for me on mac git clone https://[email protected]:username/repo_name

这在 mac 上对我有用 git clone https://[email protected]:username/repo_name