Generating a Personal Access Token in GitHub
Using a Personal Access Token or PAT is the standard way to authenticate when using the command line or the API. GitHub now offers two types: Fine-grained (recommended) and Classic.
2. Choose Your Token Type
On the left sidebar, click Personal access tokens. You will see two options:
Option A: Fine-grained tokens (Recommended)
Best for specific projects. You can limit access to specific repositories.
Click Fine-grained tokens -> Generate new token.
Name & Expiration: Give it a name and set an expiry (default is 30 days).
Resource owner: Select your account (or an organization).
Repository access: Choose “Only select repositories” to keep things secure.
Permissions: Under Repository permissions, find what you need. (For basic git actions like push/pull, set Contents to “Read and write”).
Click Generate token.
Option B: Tokens (classic)
Best for general use or older tools that don’t support fine-grained permissions.
Click Tokens (classic) -> Generate new token (classic).
Note: Enter a description (e.g., “Home PC Access”).
Expiration: Select a duration.
Scopes: For general command-line use, check the
repobox (this grants full control of private and public repositories).Click Generate token.
3. Save Your Token
[!IMPORTANT] Copy the token immediately. GitHub will never show it to you again. If you lose it, you’ll have to delete it and create a new one.
How to use it
When your terminal (or VS Code) asks for your GitHub password, paste the token instead of your actual password.
Pro-tip: If you find yourself pasting this constantly, you can save it globally using:
git config --global credential.helper store