1. Creating a token

1.1. Log in to github.com.

1.2. In the upper-right corner of any page, click your profile photo, then click Settings.

Settings icon in the user bar

1.3. In the left sidebar, click  Developer settings.

1.4. In the left sidebar, click Personal access tokens.

Personal access tokens

1.5. Click Generate new token.

Generate new token button

1.6. Give your token a descriptive name.

Token description field

1.7. To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker.

Token expiration field

1.8. Select the scopes, or permissions, you'd like to grant this token. To use your token to access repositories from the command line, select repo only.

Selecting token scopes

1.9. Click Generate token.

Generate token button

Treat your tokens like passwords and keep them secret. When working with the API, use tokens as environment variables instead of hardcoding them into your programs.


2. Using a token on the command line

Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.

For example, on the command line you would enter the following:

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS.


  • No labels