On Git, SSH, and Remote URLs

git Mar 26, 2019

I like using  GitHub Desktop to get a visual of the changes to my working repository. It's faster to view all changes in one go, and to select which files to stage for a commit. But for other interactions with Git, I'm more comfortable with typing out commands via Bash.

The other day I tried to push my new branch, but kept getting asked for GitHub credentials. No big deal - I set up my SSH key as per the GitHub documentation. However, I still kept getting asked for my username and passphrase.

After some Googling, it turned out that I originally cloned my repo via HTTPS. This meant GitHub would always ask for my password (unless I had it cached) - it would never use my SSH key as I wasn't using SSH to connect!

To fix this, I needed to convert the origin's URL to the SSH version. I copied the SSH URL for my repo and ran this command in Git Bash:

git remote set-url origin <SSH-URL-TO-REPOSITORY>

I verified that the change was applied successfully:

git remote -v

Now I could push and fetch without GitHub asking for my password.

What are some Git gotchas you've encountered? Let me know in the comments.

unsplash-logoKundan Ramisetti

Kristina Alberto

Software engineer from Sydney. I work at Domain Group.