简体   繁体   中英

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?

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: 在此处输入图像描述

在此处输入图像描述

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

As mentioned in marpo-it 's answer , the setting git.terminalAuthentication can be unchecked ( since VSCode 1.45 )

环境

That will avoid that, for Git commands invoked in the Integrated Terminal, like git push for instance, you would automatically be authenticated against your GitHub account.


Original answer:

I have set up credentials by using git config user.name "your username" and git config user.password "your password", and could see these by running git config --list , what am I missing here?

Those are not "credentials": they won't help authenticate you to a remote service like GitHub.

For HTTPS URLS ( https://github.com/<me>/<myRepo> ), you would need to:

There you would enter your actual credentials:

  • your GitHub user account name
  • your GitHub user account password (or a PAT if you have 2FA activated )

But if the issue disappear today, then this was linked to this GitHub incident .


Andreas L also mentions in the comments that trying to authenticate from an integrated VS Code terminal can be tricky.
As detailed in " git push origin master Missing or invalid credentials ", and here :

If you work with the JSON-settings file, insert the following line into it:

 git.terminalAuthentication: false,

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

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

[credential]
        helper = manager

Before it was set to wincred.

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

git@github.com:USER/REPO.git

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

This happens to me from time to time. Running vscode on win 11. I

I will get the same response Missing or invalid credentials for all interactions (clone, push, etc). I had tried various solutions without success.

I can still generate a repository password and use git clone (for example) from the command line, copying in the password when prompted. Not really ideal.

I have found the easiest & most reliable way to fix this is to reinstall Git Credential Manager Core . This is included in Git for Windows . The recommended way to install Git Credential Manager Core is just to install Git for Windows although there is also a standalone installer it seems simpler to use Git for Windows install to keep everything in line with latest. Once reinstalled my credentials are picked up again without me needing to enter them.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM