GitHub Authentication Failed Error from Command Line

GitHub Authentication Failed Error from Command Line

ยท

2 min read

After setting up my local and remote Git repositories, I couldn't able to push to my remote GitHub repository from the command line. I was getting the following error:

$ git push origin main
Username for 'https://github.com': username
Password for 'https://username@github.com': password
fatal: Authentication failed for 'https://github.com/username/my-repository.git/'

Finally, I solved this issue but I wanted to share this with others so it might be helpful.

Authenticate on Github

To solve this issue, we need to set up a personal access token (PAT) for authentication. First, we need to go to the GitHub settings, and from there we need to scroll down and click on Developer settings.

After that, we need to click on Personal access tokens and from the drop-down, select Tokens (classic).

Now, we need to click on Generate new token, and from the drop-down, choose to Generate new token (classic).

Now, you will get a personal access token and paste it into the Password for 'https://username@github.com' field when you authenticate via the command line.

$ git push origin main
Username for 'https://github.com': username
Password for 'https://username@github.com': PersonalAccessToken

Hopefully, this article will help you if you have faced a similar issue. If you found this article valuable, please consider clicking the ๐Ÿ‘‰ Follow button and giving it a few claps by clicking the โค๏ธ like button to help me create more informative content like this. Thank you for your time! ๐Ÿ–ค
Also, follow me on Medium, Twitter & LinkedIn.

Did you find this article valuable?

Support Sha Md. Nayeem by becoming a sponsor. Any amount is appreciated!

ย