Git push requires username and password
I cloned a git repository from my Github account to my PC.
I want to work with both my PC and laptop, but with one Github account.
When I try to push to or pull from Github using my PC, it requires username and password, but not when using the laptop!
I don't want to type my username and password every time I interact with origin. What I am missing here?
A common mistake is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:
git remote set-url origin git@github.com:username/repo.git
This is documented at GitHub: Switching remote URLs from HTTPS to SSH.
Permanently authenticating with Git repositories,
Run following command to enable credential caching:
$ 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>
Use should also specify caching expire ,
git config --global credential.helper 'cache --timeout 7200'
After enabling credential caching, it will be cached for 7200 seconds (2 hour) .
I just came across the same problem, and the simplest solution I found was to use SSH URL instead of HTTPS one:
ssh://git@github.com/username/repo.git
And not this:
https://github.com/username/repo.git
You can now validate with just the SSH Key
instead of the username
and password
.
上一篇: Git不断提示我输入密码
下一篇: Git推送需要用户名和密码