'Git push: Missing or invalid credentials. fatal: Authentication failed for 'https://github.com/username/repo.git'

I was trying to do my first push on a new MacBook and got this error after git push (everything worked well on my old MacBook):

Missing or invalid credentials.
Error: connect ECONNREFUSED /var/folders/tx/53fffl0j51qb47mhnlf8zsdc0000gn/T/vscode-git-1d38026c7f.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1056:14) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '/var/folders/tx/53fffl0j51qb47mhnlf8zsdc0000gn/T/vscode-git-1d38026c7f.sock'
}
Missing or invalid credentials.
Error: connect ECONNREFUSED /var/folders/tx/53fffl0j51qb47mhnlf8zsdc0000gn/T/vscode-git-1d38026c7f.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1056:14) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '/var/folders/tx/53fffl0j51qb47mhnlf8zsdc0000gn/T/vscode-git-1d38026c7f.sock'
}
remote: No anonymous write access.
fatal: Authentication failed for 'https://github.com/username/repo.git/'

Any idea why and how I can resolve it?



Solution 1:[1]

You are trying to use git from a terminal in vscode. The problem comes from the authentication handler of vscode. To solve the problem:

  • Open vscode File > Preferences > Settings
  • Search for git.terminalAuthentication
  • Uncheck the option

You have to re-open the terminal to make it work.

As of March 2022, the menus have changed a bit. Here's an illustration of how to access them: enter image description here

enter image description here

Solution 2:[2]

If you're on linux, just add sudo before the command. Otherwise, you have to add administration prefix to the command.

Solution 3:[3]

Reloading the VSCode window (shift-control-P then find Developer: Reload Window and press Enter) fixed this for me.

Solution 4:[4]

I had a similar issue. I had to modify the git config as follows:

[credential]
        helper = manager

Before it was set to wincred.

Solution 5:[5]

In my case I got the error because I was trying to push to an HTTPS remote

https://github.com/USER/REPO.git

But instead, I had to go to the repository on GitHub and copy the SSH address, which looks like this

[email protected]:USER/REPO.git

Solution 6:[6]

If You are using Windows 10. Go to control pannel and search for Windows Credential Manager. There you can find Git/bitbucket url From there You can click on edit and change your Credentials

Solution 7:[7]

Please do no downgrad if it does not apply to you, this answer may help people with below mentioed scenario.

Note: This answer is specific to people running Windows Subsystem for Linux with custom certificates for git server, it does not apply to people without WSL or WSL with no custom certificates

Check if your distro is running even as my git gogs certificate are stored and installed in WSL and without them, I can not push or pull.

For me, my vsCode was running in a remote disconnected state since WSL distro was shutdown or terminated so my certificates couldn't be aquired.

Restarting WSL distro solved the issue by reconnecting vsCode remote by providing access to my certificates.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mona Jalal
Solution 2 Triệu Phong
Solution 3 Bryan
Solution 4 Suraj Rao
Solution 5 Computer's Guy
Solution 6 Pawan Kumar Sah
Solution 7