我从我的GitHub帐户克隆了一个Git存储库到我的电脑。

我想使用我的电脑和笔记本电脑,但只有一个GitHub帐户。

当我尝试使用我的电脑推送到GitHub或从GitHub中拉取时,它需要用户名和密码,但当我使用笔记本电脑时不需要!

我不想每次与origin交互时都键入用户名和密码。我在这里缺少什么?


当前回答

您可以在Git中缓存GitHub密码:

只需遵循GitHub官方文档中的说明即可。

按照上述链接中的说明进行操作后,您应该可以在不每次输入用户名/密码的情况下,向存储库推送/从存储库中推送。

其他回答

块引用

如果您在请求用户名和密码时遇到$git推送代码问题,请执行以下步骤:

Login to your profile.
Go to settings

click developer settings
->Personal access tokens
--> note: access token
--->Select scopes: checkbox on repo
----> Generate token
-----> Make sure to copy and store it safely if you intend to reuse it.

*** use the generated token as password during pushing code for next 30days ***

***HAPPY CODING***

如果您在Windows下使用Git(例如,GitBash)(如果您不想从HTTPS切换到SSH),也可以使用Windows的Git凭据管理器

此应用程序将为您保留用户名和密码。。。

您可以在Git中缓存GitHub密码:

只需遵循GitHub官方文档中的说明即可。

按照上述链接中的说明进行操作后,您应该可以在不每次输入用户名/密码的情况下,向存储库推送/从存储库中推送。

还有一个选项:

而不是写作

git push origin HEAD

你可以写:

git push https://user:pass@yourrepo.com/path HEAD

显然,对于大多数shell,这将导致密码被缓存在历史中,所以请记住这一点。

我也有同样的问题。

所以我从项目中更改了.git/config文件,

url = https://github.com/<your-user-here>/<your-repo-here>

to

url = git@github.com:<your-user-here>/<your-repo-here>

并将SSH公钥添加到正在设置的Git配置文件中。

对于SSH公钥:

cat ~/.ssh/id_rsa.pub