How to Update GitHub Personal Access Tokens?

Personal access tokens are an alternative to authenticate GitHub users without the need of using your password. If you have used a personal access token before, during the process of generating the token you noticed you could set an expiration date. Once the expiration date is past due, the token will no longer be valid and you won’t be able to authenticate. Hence, you will need to generate a new token.

There are other cases when you forget or lose the token. GitHub gives you the possibility to regenerate the token. However, regardless of the case you are facing, I will explain how to update your personal access token using the terminal.

Step 1: Create a New Token or Regenerate an Existing Token

Go to the personal access token of your GitHub account.

  1. Open menu from the top right corner next to your profile picture.
  2. Click on Settings.
  3. Click on Developer Settings.
  4. Click on Personal access tokens.

Or you could simply click here if it is easier for you.

Creating a New Token

  1. Click on Generate new token button.
  2. Set the token expiration and scopes for the token.
  3. Click on Generate token button.
  4. Copy the token generated.

Regenerate an Existing Token

  1. Click on the token link you want to regenerate from the list of personal access tokens.
  2. Cick on Regenerate token button.
  3. Set new expiration date.
  4. Click on Regenerate token button.
  5. Copy the token generated.

Step 2: Install GitHub CLI

If you have already installed GitHub CLI, feel free to skip this step. Otherwise, it is time to install GitHub CLI.

Depending on the OS you are using, the installation should be different.

Installation for MAC users

  1. Install Homebrew if you don’t have it previously installed.
  2. Install gh using Homebrew.
     brew install gh  

Installation for Windows users

  1. Install Chocolatey if you haven’t installed it before.
  2. Install gh using Chocolatey.
     choco install gh  

If you want to see other installation alternatives, I recommend taking a look at GitHub’s CLI installation instructions.

Step 3: Update token using GitHub CLI

  1. Open the terminal
  2. Login to your GitHub account using the GitHub’s CLI.
     gh auth login  

    You will be prompted the following questions.

    • ? What account do you want to log into? GitHub.com
    • ? What is your preferred protocol for Git operations? HTTPS
    • ? Authenticate Git with your GitHub credentials? Yes
    • ? How would you like to authenticate GitHub CLI? Paste an authentication token
  3. Finally, paste your authentication token and press enter.

I tested this in both MAC and Windows and it worked correctly. I hope this tutorial helped you authenticate again to your GitHub account using personal access tokens.