简体   繁体   English

Git 推送:缺少凭据或凭据无效。 致命:“https://github.com/username/repo.git”的身份验证失败

[英]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):我试图在新 MacBook 上进行第一次推送,并在git push后出现此错误(在我的旧 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.您正在尝试从 vscode 中的终端使用 git。 The problem comes from the authentication handler of vscode.问题来自 vscode 的身份验证处理程序。 To solve the problem:解决问题:

  • Open vscode File > Preferences > Settings打开 vscode 文件 > 首选项 > 设置
  • Search for git.terminalAuthentication搜索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.截至 2022 年 3 月,菜单发生了一些变化。 Here's an illustration of how to access them:以下是如何访问它们的说明: 在此处输入图像描述

在此处输入图像描述

If you're on linux, just add sudo before the command.如果您使用的是 linux,只需在命令前添加sudo 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 )marpo-it回答中所述,可以取消选中设置git.terminalAuthentication从 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.这将避免这种情况,对于在集成终端中调用的 Git 命令,例如git push ,您将自动根据您的 GitHub 帐户进行身份验证。


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?我已经使用 git config user.name "your username" 和 git config user.password "your password" 设置了凭据,并且可以通过运行git config --list来查看这些信息,我在这里缺少什么?

Those are not "credentials": they won't help authenticate you to a remote service like GitHub.这些不是“凭证”:它们不会帮助您向 GitHub 之类的远程服务进行身份验证

For HTTPS URLS ( https://github.com/<me>/<myRepo> ), you would need to:对于 HTTPS URL( https://github.com/<me>/<myRepo> ),您需要:

There you would enter your actual credentials:在那里您将输入您的实际凭据:

  • your GitHub user account name您的 GitHub 用户帐户名
  • your GitHub user account password (or a PAT if you have 2FA activated )您的 GitHub 用户帐户密码(如果您已激活 2FA ,则为PAT

But if the issue disappear today, then this was linked to this GitHub incident .但如果问题今天消失了,那么这与 GitHub 事件有关


Andreas L also mentions in the comments that trying to authenticate from an integrated VS Code terminal can be tricky. Andreas L 在评论中还提到,尝试从集成的 VS Code 终端进行身份验证可能会很棘手。
As detailed in " git push origin master Missing or invalid credentials ", and here :详见“ git push origin master Missing or invalid credentials ”,这里

If you work with the JSON-settings file, insert the following line into it:如果您使用 JSON 设置文件,请在其中插入以下行:

 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.重新加载 VSCode window ( shift - control - P打开命令面板然后找到Developer: Reload Window并按Enter )为我修复了这个问题。

I had a similar issue.我有一个类似的问题。 I had to modify the git config as follows:我必须修改 git 配置如下:

[credential]
        helper = manager

Before it was set to wincred.在它被设置为 wincred 之前。

In my case I got the error because I was trying to push to an HTTPS remote在我的情况下,我收到了错误,因为我试图推送到 HTTPS 遥控器

https://github.com/USER/REPO.git 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但相反,我不得不将 go 到 GitHub 上的存储库并复制 SSH 地址,看起来像这样

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

If You are using Windows 10. Go to control pannel and search for Windows Credential Manager.如果您使用 Windows 10. Go 控制面板并搜索 Windows Credential Manager。 There you can find Git/bitbucket url From there You can click on edit and change your Credentials在那里你可以找到 Git/bitbucket url 从那里你可以点击编辑并更改你的凭证

This happens to me from time to time.这不时发生在我身上。 Running vscode on win 11. I在win 11上运行vscode。我

I will get the same response Missing or invalid credentials for all interactions (clone, push, etc).对于所有交互(克隆、推送等),我将得到相同的响应Missing or invalid credentials 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.我仍然可以从命令行生成存储库密码并使用git clone (例如),在出现提示时复制密码。 Not really ideal.不是很理想。

I have found the easiest & most reliable way to fix this is to reinstall Git Credential Manager Core .我发现解决此问题的最简单和最可靠的方法是重新安装Git Credential Manager Core This is included in Git for Windows .这包含在Git 中,用于 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. 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注意:此答案特定于运行Linux 的 Windows 子系统的人,带有 git 服务器的自定义证书,它不适用于没有WSL 或没有自定义证书的 WSL 的

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.检查您的发行版是否正在运行,即使我的git gogs 证书已存储并安装在 WSL 中,没有它们,我无法推送或拉取。

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.对我来说,我的vsCode在远程断开的 state 中运行,因为 WSL 发行版已关闭或终止,因此无法获取我的证书。

Restarting WSL distro solved the issue by reconnecting vsCode remote by providing access to my certificates.重新启动 WSL 发行版通过提供对我的证书的访问来重新连接 vsCode 远程解决了该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Git,致命:无法访问“https://github.com/path/to/repo.git”:gnutls_handshake() 失败:pull 函数出错 - Git, fatal: unable to access 'https://github.com/path/to/repo.git': gnutls_handshake() failed: Error in the pull function 从 Matlab 推送本地 git 存储库失败:您无法推送到 git://github.com/user/repo.git 使用 https://github.com/user/repo.git - Pushing local git repository from Matlab fails: You can't push to git://github.com/user/repo.git use https://github.com/user/repo.git 致命:拒绝 git 凭据后,“https://github.com/myrepo/frontend/”的身份验证失败 - fatal: Authentication failed for 'https://github.com/myrepo/frontend/' After denying git credentials Github 远程:未找到存储库。 致命:在 Pycharm 中找不到存储库“https://github.com/org/repo.git/” - Github remote: Repository not found. fatal: repository 'https://github.com/org/repo.git/' not found in Pycharm AWS Sagemaker 致命:无法读取“https://gitlab.com/my/repo.git”的用户名:终端提示已禁用 - AWS Sagemaker fatal: could not read Username for 'https://gitlab.com/my/repo.git': terminal prompts disabled 在 Colab 中将文件推送到 Git 时出错:致命:无法读取“https://github.com”的用户名:没有这样的设备或地址 - error when pushing files to Git in Colab: fatal: could not read Username for 'https://github.com': No such device or address 尝试推送 git 并收到“无法读取 &#39;https://github.com&#39; 的用户名:终端提示已禁用” - Attempting push on git and receiving “could not read Username for 'https://github.com': terminal prompts disabled” git push错误:无法读取“ https://github.com”的用户名:权限被拒绝 - git push error: could not read Username for 'https://github.com': Permission denied 推送失败:无法访问“ https://github.com/abc/xyz.git/”:无法解析主机:github.com - Push failed: unable to access 'https://github.com/abc/xyz.git/': Could not resolve host: github.com Git Push失败:致命:无法访问与github.com有关的未知SSL协议错误:-9805 - Git Push failed: fatal: unable to access Unknown SSL protocol error in connection to github.com:-9805
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM