Git推送需要用户名和密码

我从我的Github账户克隆了一个git仓库到我的电脑。

我想用我的个人电脑和笔记本电脑,但只有一个Github账户。

当我尝试使用我的PC向Github推送或拉出时,它需要用户名和密码,但使用笔记本电脑时不需要!

每次我与原文互动时,我都不想输入用户名和密码。 我在这里错过了什么?


常见的错误是使用默认(HTTPS)而非SSH进行克隆。 您可以通过访问您的存储库,单击“克隆或下载”,然后单击URL字段上方的“使用SSH”按钮并更新原始远程URL来更正此问题,如下所示:

git remote set-url origin git@github.com:username/repo.git

使用Git存储库永久验证身份,

运行以下命令启用凭证缓存:

$ git config credential.helper store
$ git push https://github.com/repo.git

Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>

使用时还应该指定缓存过期

git config --global credential.helper 'cache --timeout 7200'

启用凭证缓存后,它将被缓存7200秒(2小时)


我刚刚遇到同样的问题,我找到的最简单的解决方案是使用SSH URL而不是HTTPS:

ssh://git@github.com/username/repo.git

而不是这个:

https://github.com/username/repo.git

现在您可以使用SSH Key而不是usernamepassword

链接地址: http://www.djcxy.com/p/4621.html

上一篇: Git push requires username and password

下一篇: how to properly use git with network disk drives