Last updated on September 1, 2022
Last week I was working from a café and I had to pull and push code to Github. But I got the following error
ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The basic explanation for this error is that I was on an unsecured network, so the git software was not able to connect to Github through ssh. But I had to push my code. I also didn’t want to change my permanent settings on my mac to use https instead of ssh just because I was working from a coffee shop today (and then have to switch back to ssh later in the day).
The solution that I came up with is creating a remote called origin-https
which uses https while my origin
would still use ssh. Let’s dive in on how you can set it up yourself.
To add a new remote, simply use the command
git remote add origin-https https://github.com/branch-name
origin-https
is the name of the new remote followed by the URL of your repo. Notice that I have used the https URL instead of the ssh. You can get it this link from the Github repo.
You might be asked to log in using your username and a password. Confusingly enough, the password you need to enter is not your Github password.
Instead, it’s your personal access token
. This token is used to perform git operations over https in the command line. To log in, you can follow this article by Github which has done a great job at explaining how to create a personal access token and log in from your console.
If you are not prompted for your username and password, your credentials may be cached on your computer.
Now that we have successfully created the new remote, we can pull or push using the commands
Articles, guides and interviews about web development and career progression.
Max 1-2x times per month.