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 | Classic | |
|---|---|---|
| Scope | Chosen repositories with per-area permissions | Broad scopes across every repository you can reach |
| GitHub's recommendation | Use by default | Only when fine-grained cannot do the job |
| Public repos you are not a member of | Cannot contribute | Can write |
| Several organisations in one token | No | Yes |
| Packages and Checks API | Not supported | Supported |
| Limit per account | 50 | No 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.gitPaste 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
- Answer the questions in the checker to see whether a fine-grained token covers your case.
- Open your profile picture, then Settings, Developer settings, Personal access tokens, and pick the type the checker suggests.
- Set an expiry, choose repositories and permissions, generate, and copy the token at once; GitHub shows it only on creation.
- 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
- Give each token one job and the fewest repositories and permissions that job needs, so a leak exposes as little as possible.
- Always set an expiry date. A calendar reminder before it runs out beats a broken deploy on a Friday.
- Never put a token in a repository or a gist. GitHub revokes tokens it finds pushed to public repos, and private ones are still a leak.
- For servers and CI, prefer deploy keys or the platform's own short-lived credentials over a personal token tied to your account.
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.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- GitHub Webhooks: Create, Verify and Redeliver
- GitLab Webhooks: Setup, Verification and Failures
- Google Ads Conversion Tracking
- Google Ads Landing Page Experience
- Google Business Profile Not Showing on Google? Common Causes | How-to Guide
- Google Business Profile Photo Sizes, and a Checker for Your Image
- Photos on Your Google Business Profile: A Practical Guide | How-to Guide
- Google Business Profile Posts: How to Write Ones That Stay Up
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App