isak.me - a blog by isak solheim

Bi-weekly updates about things that interest me, things I have built and things I have learned.

Switching from HTTPS to SSH in git repos

This is a guide on how to resolve the following error:

Username for 'https://github.com': USERNAME
Password for 'https://USERNAME@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/USERNAME/REPO_NAME.git/'

If you are getting this error, it might be because Github no longer accepts account passwords for HTTPS requests. You will need to either set up a PAT (Personal Access Token) or SSH keys. It is recommended to use SSH.

Solution

1: Set up SSH keys for your account. To do this, you can follow this guide.

You will now need to update the local git config of the repository you are working on:

2: Open .git/config in the project's root directory.

3: Change the url field from using the HTTPS protocol to using the SSH protocol.

  • (old https) https://www.github.com/USERNAME/REPO_NAME.git
  • (new ssh) git@github.com:USERNAME/REPO_NAME.git