60

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?

one-hand-octopus
  • 2,229
  • 1
  • 17
  • 51
  • 1
    You have to set up on your new laptop the credentials to connect to github – Ôrel Jul 12 '20 at 11:22
  • 1
    "Missing or invalid credentials" I don't want to leap to conclusions but my guess is that your credentials are missing, or perhaps invalid. – matt Jul 12 '20 at 11:31
  • 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? – one-hand-octopus Jul 12 '20 at 11:36
  • 2
    There is no such config key `user.password`. See [the docs](https://git-scm.com/docs/git-config#Documentation/git-config.txt-username). – phd Jul 12 '20 at 12:07
  • Beware if you're using an integrated VS Code terminal (to avoid this, use a normal terminal instead), the following could be the issue: https://stackoverflow.com/a/63302881/12298276 – Andreas L. Jan 16 '21 at 16:26
  • @VonC I felt that selecting the most upvoted answer could help more people, but now I feel that's not fair for you so I changed it back. – one-hand-octopus Mar 22 '21 at 21:00
  • @thinkvantagedu Thank you. I did not see marpo-it's answer initially, so I have edited my answer to reference it, and to add some additional documentation. – VonC Mar 22 '21 at 21:05

9 Answers9

115

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

Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
marpo_it
  • 1,289
  • 2
  • 8
  • 9
  • 3
    For my version, it's under 'vscode / preferences / settings; under the settings for my host: extensions / git / terminal authentication' – commonpike Dec 28 '20 at 10:15
  • Here is more to read on that issue: https://stackoverflow.com/a/63302881/12298276 – Andreas L. Jan 16 '21 at 16:27
  • If you work with the JSON-settings file, insert the following line into it: `git.terminalAuthentication: false` – Andreas L. Jan 16 '21 at 16:33
  • 6
    **Try running the command from new terminal**, if it was working previously and stopped, this might work. I had renamed the origin repo and created new repo with the old origin name, so that I can push my codes to an empty repo with same name as the origin. It was giving similar error so I just tried running `git push -u origin [branchname]` from a new terminal and it worked :) – anirudh sharma Jun 22 '22 at 13:07
  • Nice solution!, I'm using ubuntu, I disabled that setting in vscode, but, I have to log out and log back into my system to kill git.vscode.sock, then everything works! – mehrdad-mixtape May 12 '23 at 17:13
28

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

li ki
  • 342
  • 3
  • 11
Bryan
  • 11,398
  • 3
  • 53
  • 78
23

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

Triệu Phong
  • 239
  • 2
  • 4
15

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

setting

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,
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Very strange, after restarting my MacBook, everything works. – one-hand-octopus Jul 13 '20 at 21:44
  • @thinkvantagedu Then this was about https://www.githubstatus.com/incidents/j597fw8kv04c – VonC Jul 13 '20 at 21:56
  • In case of using an integrated VS Code terminal, the following could be the issue: stackoverflow.com/a/63302881/12298276. In case you would like to avoid this behavior in future, open the JSON-settings file and insert the following line into it: `git.terminalAuthentication: false` – Andreas L. Jan 16 '21 at 16:37
  • @AndreasL. Thank you for this feedback. I have included your comment in the answer for more visibility. – VonC Jan 16 '21 at 16:43
  • 1
    It was working fine for me before. This issue started without any change from my side. Unchecking the `Terminal Authentication` option, reloading the terminal then checking the option and reloading the terminal again fixed it for me. – BibekStha Aug 26 '21 at 17:01
  • @BibekStha OK. What version of Git are you using? – VonC Aug 26 '21 at 17:10
  • @VonC `git version 2.24.1` – BibekStha Aug 27 '21 at 18:12
  • @BibekStha Would the issue persists/reappear with Git 2.33.0? – VonC Aug 27 '21 at 18:27
  • @VonC I provided git version of a different machine. The issue was in one of my remote machines. Git version there is `2.7.4`. – BibekStha Aug 28 '21 at 23:47
  • @BibekStha Any chance to update Git on that remote machine? – VonC Aug 29 '21 at 00:38
  • @one-hand-octopus, it might be because after restarting, the command ran in new terminal. **Try running the command from new terminal**, *if it was working previously and stopped, this might work*. – anirudh sharma Jun 22 '22 at 13:09
1

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

Computer's Guy
  • 5,122
  • 8
  • 54
  • 74
0

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

[credential]
        helper = manager

Before it was set to wincred.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

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

0

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.

robs
  • 840
  • 10
  • 15
-2

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.

Sayyed Dawood
  • 607
  • 7
  • 15