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?
If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository. Using an HTTPS remote URL has some advantages compared with using SSH.
Issue the command git fetch/push/pull. You will not then be prompted for the password.
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 [email protected]:<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 [email protected]:<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.
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"] url=https://github.com/<usr>/<repo>.git
Change to:
[remote "origin"] [email protected]:<usr>/<repo>.git
Personally, I find this a bit easier to remember at the risk of being a little more 'internal'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With