June 26, 2019
Starting this morning, I was suddenly unable to update my repositories on Github.
As I’d written about in the past, I prefer using SSH over HTTPS to connect to my repositories (mostly because it means that I don’t have to type in my username and password every time when on a trusted machine).
But, suddenly, when I tried to push, I was being prompted to do exactly that — submit my username and password. What’s worse — my combinations weren’t accepted! I’d been locked out and I didn’t know why.
$ git push Username for ‘https://github.com':
While I wasn’t able to figure out why it suddenly changed, I was able to fix it (and now know how to identify it going forward).
The steps are:
The first big thing to understand is if you’re using SSH or HTTPS.
Particularly in my case, where I was expecting to be using SSH, this wasn’t the first question I had in mind, however, answering it proved to be the key to getting to a solution.
In my case, I should have noticed immediately that I was on HTTPS because I was being prompted to submit my username for
https://… but I wasn’t thinking straight.
A cleaner way to confirm is to check where your remote repository is located:
$ git remote -v origin https://github.com/<username>/<repo name>.git (fetch) origin https://github.com/<username>/<repo name>.git (push)
Changing your remotes is probably not something you do every day, so it’s easy to forget how.
The commands are actually straightforward and the key is that the URL is different for SSH than HTTPS — again, this makes sense if you step back and think about it, but normally it just works so we don’t spend any time thinking about it.
$ ➾ git remote set-url origin firstname.lastname@example.org:stephencweiss/personal-blog.git stephen /Users/stephen/_coding/personal/blog ➾ git remote -v origin email@example.com:stephencweiss/personal-blog.git (fetch) origin firstname.lastname@example.org:stephencweiss/personal-blog.git (push)
The quick and easy way to test your SSH connection is to use the terminal command:
ssh -T <domain>.
Testing your SSH on GitHub looks like:
$ ssh -T email@example.com Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
If you get an error, it would be an indication that you would need to set it up (instructions for setting SSH up on Github).
In the heat of the moment, it’s easy to forget what problem you’re trying to solve. If you’ve been using SSH for a long time and it suddenly changes, you’re probably not paying attention to the fact that you’re being asked for a username for an HTTPS site. You’re also unlikely to be in the habit of routinely checking your remotes.
In concert, this can make a sudden change in your workflow a disorienting experience. Hopefully these tips can avoid some of the pain for next time!
Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!