Git 使用 HTTPS 访问私有存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24008982/
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
Git access to private repository using HTTPS
提问by Ask and Learn
Trying to clone a private repository I have access to using HTTPS protocol, as that is only allowed outgoing traffic.
尝试克隆我有权使用 HTTPS 协议访问的私有存储库,因为这仅允许传出流量。
git does not ask for passwords, just failed.
git 不要求输入密码,只是失败了。
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/blah/blahblah.git/info/refs
What am I missing ?
我错过了什么?
回答by codenheim
Did you try inserting the username (and optionally password) in the clone URL?
您是否尝试在克隆 URL 中插入用户名(和可选的密码)?
git clone https://[email protected]/blah/blahblah.git
or if you accept the consequences of storing your password in plain view:
或者,如果您接受以清晰可见的方式存储密码的后果:
git clone https://username:[email protected]/blah/blahblah.git
See this thread with a lot of good info:
看到这个线程有很多很好的信息:
How to provide username and password when run "git clone [email protected]"?
运行“git clone [email protected]”时如何提供用户名和密码?
EDIT: My original answer was just a quick fix, without understanding the full history of the asker, and it also works unattended, but for best security practices its better to let Git store your password. See @phpguru's answer: https://stackoverflow.com/a/29018371/257090as well.
编辑:我最初的答案只是一个快速修复,不了解提问者的完整历史,并且它也可以无人看管,但为了最佳安全实践,最好让 Git 存储您的密码。参见@phpguru 的回答:https://stackoverflow.com/a/29018371/257090 。
回答by phpguru
The answer by @mrjoltcola should work, but if you would prefer not to place your github password in your server's bash_history in plaintext on the command line then you can omit the password and be prompted for it:
@mrjoltcola 的答案应该有效,但是如果您不想在命令行上以明文形式将 github 密码放在服务器的 bash_history 中,那么您可以省略密码并提示输入:
git clone https://[email protected]/organizationname/reponame.git
Password:
I like that better.
我更喜欢那个。
回答by Eduardo Kazan
If you are using two-factor authentication, you go to this link first:
如果您使用的是双因素身份验证,请先转到此链接:
Create a token, and then use it as the password:
创建一个令牌,然后将其用作密码:
git clone https://username:[email protected]/blah/blahblah.git