github git-credential: "erase" operation not supported
Asked Answered
M

6

15

I have some trouble with the github repository I am working on. I just realised I am 3 commits ahead of main and wanted to push, but the terminal prompted the following:

git push
gh auth git-credential: "erase" operation not supported
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/name/project/'

Has anyone encountered this before and can help?

Many thanks

Magog answered 18/2, 2022 at 12:24 Comment(2)
This appears to be a problem or bug with the gh command. I updated your tags, but it's probably best to just report this directly to the gh command maintainers.Ng
Where are you running this command? My guess is that the error message is about terminal capabilities - that is, the ability of the command line environment you're in to hide characters typed as part of a password.Magistracy
F
17

You need to re-authenticate with GitHub. Run the following command and follow the prompts.

gh auth login
Feud answered 21/2, 2022 at 14:50 Comment(0)
E
12

The accepted answer didn't work for me.

I had to do gh auth refresh instead.

Evelynneven answered 3/4, 2022 at 23:11 Comment(0)
G
4

Unfortunately both gh auth login and gh auth refresh don't work for me. gh auth status shows that I'm logged in.

This came up for me on git pull and it's only happening on one repository out of many. I also haven't touched this repository for at least 3 months, so I deleted the whole folder from my local and cloned the repo again.

This fixed the issue for me.

Galton answered 9/11, 2022 at 7:0 Comment(2)
Do you use tokens? Isn't it a matter of rights associated to this token? (you have boxes to check)Frier
I was using SSH login through gh auth login, not token. I ruled out authorization issue because there was no different authorization for separate repositories. I was able to access the repo in github as well as others. After deleting the folder and cloning the repo, I was able to work normally, further ruling out auth issue.Galton
F
3

In my case, none of the other answers seemed to work.

My repo was last accessed by me 3 months ago, and since then, my Personal Access Token (PAT) expired. I also realized that my PAT was hard-coded into one of the files. So, in my case, I fixed it by following procedure:

  1. I created a new PAT by logging into Github in browser and going to Settings > Developer Settings > Personal access tokens > Tokens (classic) and using the Generate new token button.
  2. I copied the generated token.
  3. In my local directory, I went to the following file in my git synced folder: .git/config.
  4. Under [remote "origin"], the url was something like: https://username:[email protected]/username/repo-name.git. I modified it by changing old_PAT to new_PAT and saving the file.
  5. Then, running git pull origin main in Terminal worked for me.
Fidel answered 6/12, 2022 at 18:13 Comment(1)
This is a better solution for me since I need permanent access on a specific user, for automated actions, and I'm unsure if the git auth solution is permanentCortege
G
1

Just in case it helps anybody.

I have faced the same problem while executing a git push.

This situation has been this:

  • I use the same laptop for my usual day-work and my personal work. I have separate github accounts (usernames, emails etc.) for each of these two.
  • I write some code. I want to check in to a repository in my personal github.com account.
  • I do necessary housekeeping (commit, status, log etc.), to ensure that I am ready to push to my personal github account.
  • I do a git push, and I am reprimanded:

remote: Permission to {my personal github username}/-------.git denied to {my workplace github username}.

fatal: unable to access 'https://github.com/{my personal github username}/-------.git/'': The requested URL returned error: 403

From the same laptop, I submit code my workplace github too, and for good reasons, that username is the default on my laptop. So, I understand that I have to override that.

After some exploration - including visiting this page on Stackoverflow - and trying out a few things, I have taken the following steps:

First, use the gh, the github CLI tool (version 1.9.2 (2021-04-20), on Ubuntu 22.10), to check which user's credentials is being taken up by git, at the moment:

nirmalya@bluewhale:attempt_2_tac$ gh auth status
github.com
  ✓ Logged in to github.com as {my workplace github username} (/home/nirmalya/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: *******************

The output underscores the reason behind that dour response to my git push earlier.

Second, ensure that this session is brought down.

nirmalya@bluewhale:attempt_2_tac$ gh auth logout
? Are you sure you want to log out of github.com account '{my workplace github username}'? Yes /* <- default response */
✓ Logged out of github.com account '{my workplace github username}'

I am in the clear. I must be able to push now! Nah!

nirmalya@bluewhale:attempt_2_tac$ git push
Username for 'https://github.com': {my personal github username}
Password for 'https://{my personal github username}@github.com': /* I type in the password */
gh auth git-credential: "erase" operation not supported
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/{my personal github username}/whatever.git/

Third, I set myself up for a fresh login:

nirmalya@bluewhale:attempt_2_tac$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: D823-F390
- Press Enter to open github.com in your browser... 
Opening in existing browser session. 
/* at this point I move to browser and log in using my usual 2FA authentication scheme */
✓ Authentication complete. Press Enter to continue...

- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as {my prsonal github username}

Now, I am all set to push to github, it seems:

nirmalya@bluewhale:attempt_2_tac$ git push
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 1.46 KiB | 1.46 MiB/s, done.
Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/{my personal github username}/whatever.git
   aa6dc4f..b04f5e7  main -> main

Phew! :-)

Hopefully, this will save someone's time.

Grapery answered 25/11, 2022 at 5:52 Comment(0)
I
0

I have met the same error.

This is what I have done.

I have downloaded the GCM( Git credential manager) .

You can download it here : ( Installation Instructions I downloaded the deb package. Then installed it in my linux system.

sudo dpkg -i  gcm-linux_amd64.2.5.0.deb 

make sure you are in the same directory where you deb file is.

Now when I went back to my repository , and used git push GCM Interface opened up , and requested for my github token , recommended to use fine grained tokens ( Learn Here ) Put my github token , then I was asked for my gpg passphrase . How do I create a gpg passphrase ( Learn Here ) Now when I ran git push It was securely authenticated.

Imprinting answered 21/4 at 18:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.