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
- Log in to GitHub and navigate to the
Settingspage as shown below:
2. Click on
3. Click on Personal Access Tokens
4. Click on
Generate new 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
How to git push using GitHub token on the command line
Once you have a token, you can use it instead of your password when performing git push operations over HTTPS as below:
git push https://<GITHUB_ACCESS_TOKEN>@github.com/<GITHUB_USERNAME>/<REPOSITORY_NAME>.git
Note: Remember to replace
<REPOSITORY_NAME> with your token, username and repository.