使用HTTPS访问私有存储库

Ask*_*arn 39 git git-clone

尝试克隆私有存储库我有权使用HTTPS协议,因为这只允许传出流量.

git没有要求密码,只是失败了.

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/blah/blahblah.git/info/refs
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

cod*_*eim 76

您是否尝试在克隆URL中插入用户名(以及可选的密码)?

 git clone https://username@github.com/blah/blahblah.git
Run Code Online (Sandbox Code Playgroud)

或者如果您接受以简单的视图存储密码的后果:

 git clone https://username:password@github.com/blah/blahblah.git
Run Code Online (Sandbox Code Playgroud)

看到这个帖子有很多好消息:

运行"git clone git@remote.git"时如何提供用户名和密码?

编辑:我的原始答案只是一个快速修复,没有理解提问者的完整历史,它也无人值守,但为了最好的安全实践,最好让Git存储您的密码.请参阅@ phpguru的答案:https://stackoverflow.com/a/29018371/257090 .

  • 谢谢,我认为git会要求输入用户名和密码,但看起来我错了. (2认同)

php*_*uru 36

@mrjoltcola的答案应该有效,但如果您不希望在命令行上以明文形式将github密码放在服务器的bash_history中,那么您可以省略密码并提示输入密码:

git clone https://username@github.com/organizationname/reponame.git
Password:
Run Code Online (Sandbox Code Playgroud)

我更喜欢这样.


小智 6

如果您使用双因素身份验证,请首先访问此链接:

https://github.com/settings/tokens

创建一个令牌,然后使用它作为密码:

git clone https://username:token@github.com/blah/blahblah.git
Run Code Online (Sandbox Code Playgroud)