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

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

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


当前回答

我可以创建一个SSH密钥并使用它来克隆存储库。命令将保持不变:

git clone git@github.com:DriveWealth/my-repo-name.git

其他回答

如果您确定您没有启用2FA,您有权限访问回购,并且回购存在,那么您的git@github.com可能是用另一个帐户登录的。

检查一下你能做什么

ssh -T git@github.com

如果显示另一个帐户,要解决此问题:

 ssh-add -D
 ssh-add ~/.ssh/your_rsa
 ssh -T git@github.com
 git clone git@github.com:<owner_name>/<repo_name>.git

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

一旦你有了你的密钥,你必须把它添加到你的github帐户: https://github.com/settings/ssh

对于Windows用户,作为管理员运行git bash非常有用。

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

我有一个公司(私人)帐户,启用了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凭证管理器也会增加问题。我 移除了以这种方式存储的github凭据,然后移动到下面的步骤。

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

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

1)尝试使用以下格式的用户名和密码运行命令

git clone https://your_username:your_password@github.com/username/reponame.git

现在的问题是,当我们在密码中使用特殊字符时。 在Javascript中使用下面的代码将特殊字符的密码转换为UTF-8编码。

console.log(encodeURIComponent('password@$123'));

现在使用这个生成的密码,而不是使用特殊字符并运行命令。

希望这能解决问题。

对我来说,解决方案是:

git clone https://myusername@restoftherepolink.git

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

git clone https://myusername@github.com/ownersusername/repo_name.git

如果你启用了2FA,那么:

从右上角的个人资料图标进入设置或访问https://github.com/settings/profile 转到底部选项卡或转到https://github.com/settings/tokens 打开最后一个标签这里个人令牌。并生成一个令牌 复制令牌并运行git clone https://myusername@restoftherepolink.git

当提示输入密码时,把标记放在这里。