GitHub Personal Access Tokens for Git

A personal access token stands in for your GitHub password when git talks to GitHub over HTTPS or when a script calls the API. Create one under Settings, Developer settings, Personal access tokens, choose fine-grained unless you need a classic feature, and paste it when git asks for a password.

Fine-grained and classic tokens compared
Fine-grainedClassic
ScopeChosen repositories with per-area permissionsBroad scopes across every repository you can reach
GitHub's recommendationUse by defaultOnly when fine-grained cannot do the job
Public repos you are not a member ofCannot contributeCan write
Several organisations in one tokenNoYes
Packages and Checks APINot supportedSupported
Limit per account50No limit stated in the docs

Updated

GitHub stopped accepting account passwords for git over HTTPS, so cloning a private repository or pushing from a server needs a token, an SSH key or a credential manager. This page helps you choose the token type, shows where to make it, and explains the safer ways to keep it on your machine instead of pasting it every time.

Using a token with git

Sign in once with the GitHub CLI

Choose GitHub.com, then HTTPS, then sign in through the browser. The CLI sets git up to use the stored credential.

gh auth login
gh auth status
git clone https://github.com/your-org/private-repo.git

Paste the token when git asks for a password

Type your GitHub username, then paste the token as the password. A credential helper can save it afterwards.

git clone https://github.com/your-org/private-repo.git
# Username for 'https://github.com': your-username
# Password for 'https://[email protected]': <paste token>

Use a token in a script without saving it to disk

Read the token from an environment variable so it never appears in the script file or in the repository's remote URL.

export GH_TOKEN="paste-token-here"   # better: load from your secret store
curl -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/user

Storing the token instead of pasting it

GitHub's own advice is to let the GitHub CLI or Git Credential Manager handle authentication. Run gh auth login, choose HTTPS, and git commands are authenticated from then on without a token in your clipboard.

Git Credential Manager ships with Git for Windows and can be installed on macOS and Linux. It keeps credentials in the system's secure store and handles two-factor sign in through the browser.

Organisations may need to approve tokens

An organisation can require approval for fine-grained tokens, restrict them, or block classic ones. If your token works on personal repos but not on the company's, ask an organisation owner what the policy is.

How it works

  1. Answer the questions in the checker to see whether a fine-grained token covers your case.
  2. Open your profile picture, then Settings, Developer settings, Personal access tokens, and pick the type the checker suggests.
  3. Set an expiry, choose repositories and permissions, generate, and copy the token at once; GitHub shows it only on creation.
  4. Use it as the password for git over HTTPS, or better, sign in once with the GitHub CLI or Git Credential Manager so it is stored for you.

Tips

Frequently asked questions

Why does git say password authentication is not supported?

GitHub no longer accepts your account password for git over HTTPS. When git prompts for a password, paste a personal access token instead, or switch to SSH, the GitHub CLI or Git Credential Manager.

Which permissions does a fine-grained token need to push code?

Select the repositories, then under repository permissions set Contents to read and write. Add other permissions only if a script needs them, such as Pull requests or Issues.

Do personal access tokens expire?

You choose an expiry when you create one, and organisations can enforce a maximum. Separately, GitHub automatically revokes a personal access token that has not been used for a year.

How do I revoke a token?

Go to Settings, Developer settings, Personal access tokens, open the token and delete it. Any git remote or script using it stops working immediately, so replace it wherever it was stored.

Should I use a token or SSH?

Both work for git. SSH keys never expire unless you remove them and suit your own computer. Tokens suit HTTPS-only networks, scripts that also call the API, and cases where you want an automatic expiry.

Related: Git cheat sheet, Rename a git branch, API key generator, HTTP status codes.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap