克隆私人Github回购

问题描述 投票:170回答:14

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

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

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

git github private
14个回答
146
投票

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

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


3
投票

我有一个公司(私人)帐户和2因素身份验证启用,所以我必须结合几个帖子,使其工作如下。 (记下来因此对于具有相同情况的人可能有用)

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

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

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

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

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

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

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

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

请注意:如果在Windows Credential Manager中为您的帐户存储了错误的密码,它也会增加问题。在移至下面的步骤之前,我删除了以这种方式存储的github凭据。

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

现在弹出Windows Credential管理器。我在文本框中键入了我的用户名和密码(这接受了我的密码有$符号)并提示我输入双因素身份验证代码。我从Google身份验证器输入了身份验证代码,克隆启动完美。


2
投票

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


1
投票

如果新使用的计算机具有运行此命令的不同凭据

git clone https://github.com/username/reponame.git

直接不行。 Git将尝试使用存储的凭据,不会提示您输入用户名和密码。由于凭据不匹配,git将输出Repository not found并且克隆操作失败。我解决它的方法是删除旧凭据,因为我不再使用它们,并再次运行上面提到的命令并输入所需的用户名和密码并克隆私人仓库。


0
投票

在github中添加桌面ssh公钥。

https://github.com/settings/keys

您可以在没有任何密码的情况下克隆存储库。


0
投票

我需要一种非交互式方法来克隆私人仓库。

灵感来自这个问题:https://github.com/github/hub/issues/1644

步骤1。

在github开发人员设置中创建个人访问令牌:https://github.com/settings/tokens

第2步。

git clone https://$token:[email protected]/$username/$repo.git

119
投票

这对我有用:

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

当然,这是在adding my SSH key to Github之后。我在CentOs服务器上使用它,如果有必要的话。


42
投票

这对我有用:

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

32
投票

看在上帝的份上,我已经多次遇到过这个问题,每次登陆这个页面,都会尝试一切并失败!

这是因为我启用了2FA!

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

如果您启用了two-factor authentication,或者您正在访问使用SAML single sign-on的组织,则必须使用provide a personal access token而不是输入HTTPS Git的密码。

  1. 关注this link并创建一个访问令牌
  2. git clone https://github.com/username/repo_name.git(默认的git repo链接已经足够了!)
  3. 输入您的用户名并使用访问令牌作为密码!

更新:

  • 如果您不介意在命令行中公开访问令牌,您还可以将访问令牌粘贴为用户名,然后按Enter键输入(不需要密码)。
  • 讨厌一遍又一遍地复制和粘贴访问令牌? 使用git config credential.helper store(不要在你不信任的机器上这样做)

17
投票

使用Git for Windows可以更轻松地使用HTTPS网址。

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


6
投票

对我来说,解决方案是:

git clone https://[email protected]

在这里你需要成为回购的所有者,但如果你不是,那么它将成为

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

如果你有2FA enabled那么:

  1. 从右上角的配置文件图标转到设置或访问https://github.com/settings/profile
  2. 转到底部标签或转到https://github.com/settings/tokens
  3. 在这里打开最后一个标签个人令牌。并生成一个令牌
  4. 复制令牌并运行git clone https://[email protected]

当提示输入密码时,将该令牌放在此处。 Token generation image here


5
投票

为了回应mac的回答,您可以在github repo页面上获取SSH克隆URL,方法是单击SSH上的You can clone with HTTPS, SSH, or Subversion.并复制URL。


3
投票

除了MK Yung的回答:如果您不想收到403 Forbidden响应,请确保在部署到repo的部署密钥的任何地方添加公钥。


3
投票

首先确保您有一个SSH密钥或生成一个:https://help.github.com/articles/generating-ssh-keys/

获得密钥后,必须将其添加到您的github帐户:https://github.com/settings/ssh

对于Windows用户,以管理员身份运行git bash很有用。

现在克隆应该适用于私有存储库(repo),而不必输入您的用户名和密码。

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