036. git push 时,每次都要输入用户名和密码(问题) - cwy007/tips-and-skills GitHub Wiki

1. 第一种解法

change the .git/config file from my project

url = https://github.com/<your-user-here>/<your-repo-here>
to
url = [email protected]:<your-user-here>/<your-repo-here>

and add the ssh public key to the git profile which is in setting.

for ssh public key

cat ~/.ssh/id_rsa.pub

3. 第二种解法

For the uninitiated who are confused by the previous answers, you can do:

git remote -v

which will respond something like

origin  https://[email protected]/yourname/yourrepo.git (fetch)
origin  https://[email protected]/yourname/yourrepo.git (push)

then you can run the command many other have suggested, but now you know yourname and yourrepo from above, so you can just cut and paste yourname/yourrepo.git from above into

git remote set-url origin [email protected]:yourname/yourrepo.git

3. 参考链接

https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password