Why is github asking me username/password although I setup SSH authentication?

本小妞迷上赌 提交于 2020-12-29 03:45:20

问题


I have followed these instructions to set up the SSH key for github. But now when I do

> git pull
Username for 'https://github.com': 

in a repository on the local computer I have taken the public SSH key from, I am still asked for a username/password. Did I miss a step?


回答1:


You need to tell Git to use SSH protocol instead of HTTPS. On the repository page on GitHub, select Clone or Download and Use SSH. You will get a URL for the SSH protocol in the form git@github.com:<user>/<repo>.git.

Then run the following command in your working tree to tell Git to use this URL instead of the current one:

git remote set-url origin git@github.com:<user>/<repo>.git

This is also explained in the GitHub Help.

The method above won’t cause the repository to be cloned again, it just changes the communication protocol used for future synchronization between your local repo and GitHub.

Alternatively, you could set up a new remote using git remote add <new-remote-name> <url> and then git pull <new-remote-name> but Git would keep track of both protocols as separate remotes, so I do not recommend this.




回答2:


This can also be done by editing the git config file for your project. With your favourite editor open .git/config and find the existing URL:

[remote "origin"]j
    url=https://github.com/<usr>/<repo>.git 

Change to

[remote "origin"]j
    url=git@github.com:<usr>/<repo>.git 

Personally I find this a bit easier to remember at the risk of being a little more 'internal'.



来源:https://stackoverflow.com/questions/46337566/why-is-github-asking-me-username-password-although-i-setup-ssh-authentication

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!