In my case, I have created my own repo on GitHub, and wanted to push files to that repo from my local machine. When I wanted to push the code, I was asked to type the username and password though I have configured my GitHub account with a public SSH key.
My mistake was that I have added the remote with https
end-point instead of the ssh
one, as follows:
git remote add origin https://github.com/vagdevik/dummy.git
I fixed the issue by:
(The following points are important because, if we directly jump to step 2, it throws an error saying that the remote already exixts)
- Removing the
.git
and initialize the tracking again:
rm -rf .git
Initialize the git tracking again, added files to track, and committed :
git init
git add .
git commit -m "first commit"
Note: I didn't do any previous commits to this repo, so removing .git
doesn't hurt. If you don't want to lose the changes you made to your repo, please follow this.
- Now, add the SSH remote as follows, instead of the one with
https
endpoint(IMPORTANT)
git remote add origin git@github.com:vagdevik/dummy.git
This time, I was not asked to enter username/password.
Thanks!