Cloned GitHub repos ask for a password, while originally created don’t

gitgithub

I've just lost a bunch of repositories from my disk, so I've cloned them from GitHub. These are now asking for username and password each time I push something to GitHub. Those that haven't been deleted don't do that.
The only solution I've read for getting rid of username/password prompt is generating ssh key. The thing is I already have a key, otherwise I couldn't push without prompts in those repos, that I didn't clone.

I've looked at git config for two of my repositories, one that I can push without password and one that I've cloned. The only difference was branch.master.remote and branch.master.merge settings, which I unset, making git config the same. But the prompt is still there.

I'm not even sure that generating new ssh key will work. What are my options?

Best Answer

My guess:

Your old repositories used SSH remotes (git@github.com: or ssh://git@github.com/ prefixes), which used public-key authentication. (In fact, the Github SSH server never asks for a password.)

Your new repositories use HTTP remotes (https://username@github.com/), which only support password-based HTTP Basic authentication and do not use your SSH keys.

Change your remote URLs to use SSH again. Use git remote set-url or edit .git/config to do this. Replace

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

with just

git@github.com:username/repo.git

You can even have an entry in your ~/.gitconfig that tells git to translate remote URLs from HTTP or Git to SSH.

This way, if your repository is configured for a HTTP or Git remote, git will ignore that setting when pushing and will use SSH instead.

[url "git@github.com:"]
    pushInsteadOf = git://github.com/
    pushInsteadOf = https://github.com/

(An insteadOf = setting is also possible, to override both pulling and pushing.)

Related Question