git 使用用户名和密码克隆 github 的私有仓库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22755268/
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
Clone a private repo of github with username and password
提问by Usman Afzal
I have configured Account A on my system with Global configurations and I can clone all my repos from there.
我已经使用全局配置在我的系统上配置了帐户 A,我可以从那里克隆我的所有存储库。
Now I don't want to change the configuration and I want to clone and do all operations of account B with my username and password. How can I do this?
现在我不想更改配置,我想使用我的用户名和密码克隆并执行帐户 B 的所有操作。我怎样才能做到这一点?
I have tried:
我试过了:
git clone username:[email protected]:*****/******.git
But with no success.
但没有成功。
回答by VonC
You can try with the complete https url:
您可以尝试使用完整的 https 网址:
git clone https://username:[email protected]/*****/******.git
If you omit the https://
part (and use ':
' instead of '/'), it would be interpreted like an ssh url.
如果省略该https://
部分(并使用 ' :
' 而不是 '/'),它将被解释为 ssh url。
The GitHub help page "Which remote URL should I use?" confirms an https url can access private repos.
GitHub 帮助页面“我应该使用哪个远程 URL?”确认 https url 可以访问私有存储库。
Note: I wouldn't put the password directly in the url, but use a credential manager to get the right password for the right user.
注意:我不会将密码直接放在 url 中,而是使用凭证管理器为正确的用户获取正确的密码。
git clone https://[email protected]/*****/******.git
回答by GraSim
Just to make the syntax a bit clearer, to clone a private repository use:
只是为了使语法更清晰,克隆私有存储库使用:
git clone https://[insert username]:[insert password]@github.com/[insert organisation name]/[insert repo name].git
Example:
例子:
git clone https://myusername:[email protected]/myorgname/myreponame.git