Personal Access Token (PAT)

Kabeer ShoaibKabeer Shoaib
2 min read

A Personal Access Token (PAT) is like a password, but even more secure and customizable. It allows you to authenticate with GitHub and perform actions (like pushing code) from your terminal, especially after GitHub removed support for password authentication over HTTPS.


Why Use a Personal Access Token?

GitHub disabled the use of account passwords for Git operations over HTTPS to enhance security. Instead, you must use:

  • SSH key authentication or

  • Personal Access Tokens (PATs)


When Do You Need a PAT?

You need a PAT when:

  • You're pushing code to GitHub via HTTPS

  • Using the GitHub API

  • Using GitHub CLI or other tools that access your repositories


How to Create a Personal Access Token

Step 1: Log into GitHub

Go to https://github.com

Step 2: Go to Developer Settings

  • Click your profile icon in the top-right corner

  • Select Settings

  • Scroll down and click Developer settings

Step 3: Create a Token

  • Click Personal access tokens > Tokens (classic)

  • Click Generate new token

  • Choose a name and expiration date

  • Select the scopes (permissions) you need (e.g., repo, workflow)

  • Click Generate token

⚠️ Important: Copy the token immediately after generating it. You won’t be able to see it again!


How to Use the Token

When prompted for a username and password in your terminal:

  • Enter your GitHub username as the username

  • Paste your Personal Access Token as the password

git push origin main
Username: your-username
Password: <your-token-here>
0
Subscribe to my newsletter

Read articles from Kabeer Shoaib directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kabeer Shoaib
Kabeer Shoaib