Authenticating with GitHub using Personal Access Tokens

As of August 13, 2021, GitHub no longer supports password authentication for Git operations. Instead, users are required to use Personal Access Tokens (PATs) to authenticate their interactions with the platform. In this tutorial, we will explore how to create and use PATs on various operating systems, including Windows, macOS, and Linux.

Creating a Personal Access Token on GitHub

To get started, you need to create a Personal Access Token on your GitHub account. Here’s how:

  1. Log in to your GitHub account and navigate to the Settings page.
  2. Click on Developer Settings and then select Personal Access Tokens.
  3. Click on Generate New Token and follow the prompts to create a new token.
  4. Give your token a name and select the scopes you want to grant it.
  5. Click on Generate Token and copy the token to a safe location.

Using Personal Access Tokens on Windows

To use your PAT on Windows, you need to update your Credential Manager:

  1. Open the Credential Manager from the Control Panel.
  2. Select Windows Credentials and find the entry for git:https://github.com.
  3. Edit the password by replacing it with your GitHub Personal Access Token.
  4. Click OK to save the changes.

Alternatively, if you don’t have an existing entry, you can create a new one:

  1. Click on Add a generic credential.
  2. Enter git:https://github.com as the Internet address.
  3. Type in your GitHub username and paste your PAT as the password.
  4. Click OK to save the changes.

Using Personal Access Tokens on macOS

To use your PAT on macOS, you need to update your Keychain:

  1. Open the Keychain Access app.
  2. Search for github.com and select the Internet password entry.
  3. Edit the password by replacing it with your GitHub Personal Access Token.
  4. Click Save Changes to save the updates.

Using Personal Access Tokens on Linux

To use your PAT on Linux, you need to configure your Git client:

  1. Run the command git config --global user.name "your_github_username" to set your username.
  2. Run the command git config --global user.email "your_github_email" to set your email address.
  3. Run the command git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY to clone a repository.
  4. When prompted for a password, enter your GitHub Personal Access Token.

You can also cache your credentials using the git config --global credential.helper cache command.

Using Personal Access Tokens with JetBrains IDEs

If you’re using a JetBrains IDE, such as IntelliJ or PyCharm, you can register your PAT in the IDE settings:

  1. Open the Settings page and navigate to Version Control | GitHub.
  2. Click on the Add button and select Log In with Token.
  3. Enter your GitHub Personal Access Token and click Add Account.

Alternative Method

You can also use your PAT directly in the Git URL:

git remote set-url origin https://<githubtoken>@github.com/<username>/<repositoryname>.git

Or when cloning a repository:

git clone https://<username>:<githubtoken>@github.com/<username>/<repositoryname>.git

This method works on all operating systems, but you need to remember to update each repository individually.

Leave a Reply

Your email address will not be published. Required fields are marked *