Github – Password authentication is not supported for Git operations

Bash
$ git push -u origin main 
remote: Invalid username or token. Password authentication is not supported for Git operations.

From 2021-08-13, GitHub is no longer accepting account passwords when authenticating Git operations. You need to add a PAT (Personal Access Token) instead, and you can follow the below method to add a PAT on your system.

Create Personal Access Token on GitHub
From your GitHub account, go to Settings → Developer Settings → Personal Access Token → Tokens (classic) → Generate New Token (Give your password) → Fillup the form → click Generate token → Copy the generated Token, it will be something like github_pat_sFhFsSHhTzMDreGRlJjmks4Tzugthdvfsra

Main Permission Categories for Fine‑Grained PATs

Here are the broad categories of permissions you can assign via a fine‑grained PAT, then some representative sub‑permissions for each. Read More

Repository‑level permissions

These control access to repository content, issues, PRs, workflows, secrets, etc.

Permission AreaWhat it allows
ContentsRead / write repository files (code, docs), push commits, create branches, rename branches, etc.
MetadataRead repo metadata: repo info, collaborators, contributors, forks, license, languages, etc.
Pull requestsRead / write PRs: view PRs, create, update, merge, comment, etc.
IssuesRead / write issues: create issues, edit, comment, close or reopen, etc.
Commit statusesCreate or update commit statuses — used by CI/CD to mark builds as pass/fail, etc
Deployments & EnvironmentsManage deployments, deployment statuses, environment‑specific configs
Secrets / VariablesRead or manage repo‑level secrets, environment variables — for workflows, actions, or other automations
WebhooksRead / create / update webhooks on the repo (to trigger external integrations)
Workflows / ActionsManage workflows: create/edit workflow files, trigger workflows, manage artifacts, caches, logs
PagesManage GitHub Pages for repo: set up pages, builds, deployments
Security Features (e.g. dependabot alerts, secret‑scanning alerts, repo security advisories)Read or handle security-related alerts / scanning / advisories for the repo

Typical Minimal Sets (What You Usually Need)

Depending on what you want to do with a PAT — here are minimal or common combinations:

  • Push/pull code (HTTPS) in a private repo: Contents (read & write) + Metadata (read), maybe Commit statuses if using CI.
  • Open issues, manage PRs: add Issues (read/write) and Pull requests (read/write).
  • Run automation, CI, workflows, manage secrets: include Workflows, Secrets / Variables, Deployments / Environments as needed.
  • Use token for repo monitoring or read‑only scripts: only need Metadata + maybe Contents (read) — avoid granting write access.

Because fine‑grained PATs let you pick exactly what you need, it’s recommended you only grant the permissions the specific use‑case requires (principle of least privilege). Read More

Lets get started!

On Linux, you need to configure the local GIT client with a username and email address:

$ git config --global user.name "your_github_username"
$ git config --global user.email "your_github_email"
$ git config -l

Once GIT is configured, we can begin using it to access GitHub. Example:

$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
> Cloning into `YOUR-REPOSITORY`...
Username: <type your username>
Password: <type your personal access token>

Now cache the given record in your computer to remembers the token:

$ git config --global credential.helper cache

If needed, anytime you can delete the cache record by:

$ git config --global --unset credential.helper
$ git config --system --unset credential.helper

Now try to pull with -v to verify

$ git pull -v