我在Github上有一个私人存储库用于我正在进行的项目。到目前为止,我只在我的家用台式机上工作,但我刚买了一台笔记本电脑,并且我正在设置它,以便我可以从任何一台计算机上工作,并推/拉更改。
我为笔记本电脑的Github帐户添加了一个新的SSH密钥,并成功克隆并更改了我设置的公共测试仓库。但是,我无法克隆私人仓库。在命令行中我需要做些什么特别的事情才能克隆私人仓库?我是否需要为笔记本电脑设置一个新的GitHub帐户并将自己设置为合作者?
我使用的命令是git clone git://github.com/myusername/reponame.git
私有克隆URL采用[email protected]:username/repo.git
形式 - 也许您需要使用git@
而不是git://
?
git://
URL是只读的,看起来私有存储库不允许这种形式的访问。
我有一个公司(私人)帐户和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身份验证器输入了身份验证代码,克隆启动完美。
这对我在mac git clone https://[email protected]:username/repo_name
上工作
如果新使用的计算机具有运行此命令的不同凭据
git clone https://github.com/username/reponame.git
直接不行。 Git将尝试使用存储的凭据,不会提示您输入用户名和密码。由于凭据不匹配,git将输出Repository not found
并且克隆操作失败。我解决它的方法是删除旧凭据,因为我不再使用它们,并再次运行上面提到的命令并输入所需的用户名和密码并克隆私人仓库。
我需要一种非交互式方法来克隆私人仓库。
灵感来自这个问题:https://github.com/github/hub/issues/1644
步骤1。
在github开发人员设置中创建个人访问令牌:https://github.com/settings/tokens
第2步。
git clone https://$token:[email protected]/$username/$repo.git
这对我有用:
git clone https://[email protected]/username/repo_name
当然,这是在adding my SSH key to Github之后。我在CentOs服务器上使用它,如果有必要的话。
这对我有用:
git clone https://username:[email protected]/username/repo_name.git
看在上帝的份上,我已经多次遇到过这个问题,每次登陆这个页面,都会尝试一切并失败!
这是因为我启用了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的密码。
git clone https://github.com/username/repo_name.git
(默认的git repo链接已经足够了!)更新:
git config credential.helper store
(不要在你不信任的机器上这样做)使用Git for Windows可以更轻松地使用HTTPS网址。
打开一个git shell然后git clone https://github.com/user/repo
。出现提示时输入用户名和密码。无需设置SSH密钥。
对我来说,解决方案是:
git clone https://[email protected]
在这里你需要成为回购的所有者,但如果你不是,那么它将成为
git clone https://[email protected]/ownersusername/repo_name.git
如果你有2FA enabled
那么:
git clone https://[email protected]
为了回应mac的回答,您可以在github repo页面上获取SSH克隆URL,方法是单击SSH
上的You can clone with HTTPS, SSH, or Subversion.
并复制URL。
除了MK Yung的回答:如果您不想收到403 Forbidden响应,请确保在部署到repo的部署密钥的任何地方添加公钥。
首先确保您有一个SSH密钥或生成一个:https://help.github.com/articles/generating-ssh-keys/
获得密钥后,必须将其添加到您的github帐户:https://github.com/settings/ssh
对于Windows用户,以管理员身份运行git bash很有用。
现在克隆应该适用于私有存储库(repo),而不必输入您的用户名和密码。