GitHub change from password to personal access token without re-cloning the repo
Asked Answered
R

2

7

As of today seems GitHub has disabled passwords through the command line and instead requires personal access tokens, as you get this error when trying to push a commit: "remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead."

I went and generated a personal access token, but most of the tutorials I've seen say that you essentially should reclone the repo again, and then "log in" with your personal access token before you can commit again.

However, I have a lot of repos that use the older password method, and I'd rather not reclone every single one. Is there a way to somehow tell Git, "hey I'd like to change my password for login" in my current repos. I was hoping when I pushed I would automatically just be prompted for my password again, but instead I'm just given the error message above, and I don't see how I can re-enter my login info without recloning and trying to push again.

I tried git config --global --unset user.password but that didn't seem to fix the issue.

Thanks

Risotto answered 13/8, 2021 at 17:33 Comment(5)
There is no user.password setting. We see this exact item (user.password) a lot here, implying there's some sort of bad tutorial or help-system thing out there claiming that there is such a setting. It would be good to get this fixed at its root. Do you remember why you thought user.password might exist?Cumber
Yeah I think it's because I saw it here: https://mcmap.net/q/20179/-how-can-i-save-username-and-password-in-git when I was just skimming through, I see now that the answer says you shouldn't do this though/it's old, outdated, and insecureRisotto
@Cumber Indeed 'git config -l' does not list any 'user.password'. However, in ubuntu 18.04 after a github token expiration, I used the command 'git config --global --unset user.password' . After that git did ask again for username/password. I have used that in the past again. Would love to find out why it works, and why it should not. That is why I post that after reading your comment. PS I did not reclone my repo.Ration
@SpyrosK: Hm, so maybe there is some (non-Git) software that reads user.password as part of a (not Git supplied) credential helper. It would be good to track this down...Cumber
@Cumber If the git credential store ( git-scm.com/docs/git-credential-store ), then this could be an explanation. However I a first glance of the documentation did not provide any evidence.Ration
R
7

Update: Figured it out and figured I'd leave this question up since seems relevant due to this recent change. For people on a Macbook, go to KeyChain Access from the Finder, and search for github. Double click the github.com option: enter image description here

press the show password button on the menu that pops up, and swap that out for your personal access token generated.

Risotto answered 13/8, 2021 at 17:38 Comment(2)
This is not a good solution for MacOS users. It replaces your login credentials for safari, and may break subsequent third party oauth links to your github account depending on token permissions.Rudolfrudolfo
You should create an entry with name=git:github.com, Kind=Programme password, Account=your github username, where=git:github.com. The cleanest way to do this however is to brew install gh and then run gh auth login. This adds the correct entry into your keychain (see: https://mcmap.net/q/47181/-use-token-to-push-some-code-to-github-quot-support-for-password-authentication-was-removed-quot-duplicate).Rudolfrudolfo
I
0

On Windows, open Credential Manage and edit git:github credentials copy-pasting your generated token into the password field.

enter image description here

Ieper answered 13/8, 2021 at 21:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.