“Why is Github asking me to input my username and password when I try to push changes to a repository I own?” I asked this myself a couple of times before I figured out I had cloned it the wrong way:
git clone https://github.com/kovshenin/publish.git .
As opposed to:
git clone git@github.com:kovshenin/publish.git .
Where the former will use the HTTP protocol, and thus require basic authentication (username and password), and the latter will use the SSH protocol, and will try to use my SSH key instead, for password-less authentication. The former will work, but you’ll have to keep entering your username and password every time. The latter is more secure.
Simple, but tricky. No, I don’t use a GUI for version control, and neither should you, trust me :)
To fix that issue, run git remote set-url origin git@github.com (whatever the ssh url is)
Sweet, didn’t know that! Thanks John :)
Had the very same problem a week back and set the other origin (as per John’s advice and Github’s help – https://help.github.com/articles/why-is-git-always-asking-for-my-password )
Cool, that’s easier that removing everything and cloning from scratch like I did :) Thanks for the link!
Https can be useful when deploying to shared environments, and you’re either unable or unwilling to set up an RSA key on the server
That’s a good point Neil, I can totally see how I’d use that on a remote server, which needs to only pull. Thanks for your comment!
Konstantin, thanks for the great tip! I was still thinking so until the last 2 minutes. So basically, if I use the 2nd method, the password will be saved/cached automatically?
Hi M! No, in the second method your GitHub password is not used at all, which makes it more secure. Instead of using a password, GitHub will authenticate you by an RSA key. You can learn more about SSH keys in this GitHub article.
Thanks for your comment :)