change origin of github repo from 'https:'' To 'ssh'

Recently, while trying to push to a new repo on Github, I kept getting this error: “remote: Invalid username or password.
fatal: Authentication failed for ‘https://github.com/username/repo.git/‘“.

It took me a bit to realize that I had accidentally cloned the https: version of the repo instead of the ssh version.

Here’s the fix.

1
2
3
git remote -v
git remote remove origin
git remote add origin git@github.com:user/repo.git

This deletes that which points to the https: and adds the ssh version of the repo.