How to authenticate to GitHub using username and password

By

Learn how to authenticate to GitHub when username and password no longer work, by creating a personal access token with repo scope to use as the password.

~~~

You can’t authenticate to GitHub with your account password any more, at least not for Git operations. GitHub removed password authentication for Git in August 2021. What you do instead is create a personal access token and paste it wherever the password used to go.

Here’s how I ran into this, and how I fixed it.

I was setting up a new editor and I was trying the GitHub push workflow.

I committed my changes, pressed “Push” and I got a dialog window to enter my GitHub username and password.

On GitHub I have 2FA set up, so you can’t just login using those credentials. And even without 2FA, GitHub stopped accepting the account password for pushes and pulls. The dialog still says “password”, but what it really wants is a token.

Why did GitHub do this?

A password unlocks your whole account. A token doesn’t. You can give it only the permissions it needs, revoke it at any time without changing your password, and create a separate one for each app.

That’s why the fix is a personal access token that’s tied to the app, with the permission needed.

How to create a personal access token

Go to the GitHub settings, and locate Developer Settings:

GitHub settings sidebar with Developer settings option highlighted

Click Personal access tokens:

GitHub Developer settings page showing Personal access tokens section with Generate new token button

Now add a name so you’ll remember what this token is for, set the expiration to “No expiration” and enable the repo scope. That’s the only one you need to push and pull:

New personal access token form with note field, expiration dropdown, and scopes list including repo scope

Token expiration set to No expiration with repo scope checked and enabled for full control of private repositories

I picked “No expiration” because this was for my own editor on my own machine. An expiring token is safer, but then you have to repeat this dance when it runs out. Your call.

Save and you’ll be able to see the token.

Personal access tokens list showing the newly created Nova editor token with repo scope and no expiration date

Copy it now. GitHub shows the token only once, on this page. If you close the tab without copying it, there’s no way to see it again, and you’ll have to regenerate it.

Use the token as the password

Now enter this token as the password in the username/password dialog window. The username stays your normal GitHub username.

Most editors and operating systems store the credentials after the first successful push, so you won’t be asked again. On macOS they end up in the Keychain.

You’re set.

Tagged: Git · All topics
~~~

Related posts about git: