git push using GitHub token [Deprecating password authentication]

I am using git for version control and GitHub for the repository of my code development. Every git push of my work to the repository is prompted to input my GitHub username and password. I would like to avoid it for every push, but how to setup git push to use GitHub token.


Password-based authentication for Git is deprecated and you should make the push based on the token authentication. GitHub has personal access token (PAT), to use in place of a password with the command line or with the API. Below is how to generate the token and use it:

Create a token in GitHub

  1. Log in to GitHub and navigate to the Settings page as shown below:

GitHub settings menu

2. Click on Developer Settings

GitHub Developer Settings

3. Click on Personal Access Tokens

How to create personal access token in GitHub

4. Click on Generate new token

git push using GitHub token

5. Now type in the name of the token and select the scopes, or permissions, you’d like to grant this token. Make sure you select repo to use your token to access repositories from the command line. Click Generate token.

Scope for the token


Make sure to copy your personal access token immediately. You won’t be able to see it again!

How to git push using GitHub token on the command line


Personal Access Tokens (PAT) can only be used for HTTPS git operations. Switch your repository to HTTPS if it is using SSH.

Once you have a token, you can enter it instead of your password when performing git push operations over HTTPS as below:


Note: Remember to replace <GITHUB_ACCESS_TOKEN>, <GITHUB_USERNAME>, <REPOSITORY_NAME> with your token, username and repository.

Updated on July 9, 2021

Was this article helpful?

Related Articles

Leave a Comment