使用用户名和密码克隆私有github仓库

28

我在系统中配置了账户A的全局设置,现在可以从那里克隆所有我的仓库。

现在我不想改变配置,我想使用我的用户名和密码克隆并执行账户B的所有操作。我应该怎么做?

我尝试了:

git clone username:passwordgit@github.com:*****/******.git

但是没有成功。

2个回答

54

您可以尝试使用完整的https网址:

git clone https://username:<token>@github.com/*****/******.git
如果省略https://部分(并使用“:”代替“/”),它会被解释为ssh url。GitHub帮助页面“Which remote URL should I use?”确认https url可以访问私有repo。注意:我不会直接在url中放置令牌,而是使用凭据管理器获取正确用户的正确密码
git clone https://username@github.com/*****/******.git

提醒: 自 2021 年 8 月起,GitHub 要求所有经过身份验证的 Git 操作必须使用令牌(或 SSH 密钥)进行身份验证。
在这里,所提到的令牌是一个PAT (个人访问令牌)


1
当启用双因素身份验证时,您需要生成一个临时访问令牌。https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled - mission.liao
1
@mission.liao 我同意。我在https://dev59.com/XGYr5IYBdhLWcg3wR4Us#18607931中描述了PAT(个人访问令牌)。 - VonC
@alhelal应该遵循相同的原则,所以是的,它也应该适用于Bitbucket。 - VonC

17

为了使语法更清晰,克隆私有仓库请使用:

git clone https://[insert username]:[insert password]@github.com/[insert organisation name]/[insert repo name].git
或者
git clone https://[insert username]@github.com/[insert organisation name]/[insert repo name].git

示例:

git clone https://myusername:mypassword@github.com/myorgname/myreponame.git

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接