How to fix Git for Windows keeps asking for Github credentials

huangapple go评论68阅读模式
英文:

How to fix Git for Windows keeps asking for Github credentials

问题

I will provide the translation of the code part as requested:

我总是通过HTTPS克隆私有Github存储库。我有个个人访问令牌可用作第一次运行git命令时要求输入的“密码”。

很长一段时间以来,我能够在命令行中运行git操作而不需要每次运行命令时都输入凭据。

但是这些天,每次在命令行中运行git命令时都会要求输入凭据!

我尝试了各种组合来更改git配置的credentials.helper(更改为store/wincred/manager/cache)以及其他很多方法,但都不起作用。

有趣的是,如果我在VSCode终端中运行git命令,它就不会要求输入凭据,而会直接工作。但我不想每次需要进行一些git操作时都启动VSCode(特别是当我的计算机由于其他任务而内存不足时)。

我需要一种永久性解决这个问题的方法,同时仍然使用HTTPS远程URL和个人访问令牌。

我正在使用Git for Windows的git版本2.40.0.windows.1

在尝试了许多在线指南后,我的当前可怕的.gitconfig如下:

[credential "github.com"]
	authority = Github
	interactive = never
	preserve = true
[credential]
	helper = manager
	modalPrompt = true
	writelog = true

Please note that this translation is for the code portion only, as per your request.

英文:

I always clone private Github repos via HTTPS. I have personal access token to use as "password" when git asked for it for the first time.

For a very long time, I was able to do git operations without git asking for credentials for every single command when I run things in command line.

But these days it always ask for credentials in command line!

I have tried various combinations for changing git config credentials.helper (changing to store/wincred/manager/cache) and a bunch of other things, nothing works.

Funny thing is, if I run git command inside VSCode terminal, then it will not ask for credentials and just work. But I do not want to have to fire up VSCode every time I need to do some git stuffs (especially when my computer is running low on RAM due to other tasks)

I need a permanent way to fix this issue while still using HTTPS remote url + personal access token

I am using Git for Windows git version 2.40.0.windows.1

My current horrible .gitconfig after trying many online guides

[credential "github.com"]
	authority = Github
	interactive = never
	preserve = true
[credential]
	helper = manager
	modalPrompt = true
	writelog = true

答案1

得分: 3

我终于找到了根本原因

显然是因为 git-credential-manager.exe 没在 PATH 中找到

一旦我执行 set PATH=C:\Git\mingw64\bin;%PATH% 并执行一次 git push,我会看到网页浏览器中的 Github 登录提示,之后一切都正常工作了

英文:

I finally found the root cause

Apparently it is because git-credential-manager.exe is not found in PATH

Once I do set PATH=C:\Git\mingw64\bin;%PATH% and do one git push, I am prompted with web browser Github login, and then things just work now

答案2

得分: 2

在Windows上使用manager-core并指定提供程序。对于GitHub,我们想要GitHub提供程序,Bitbucket有一个Bitbucket提供程序,还有一个用于正常使用的通用提供程序。

因此,要设置通用提供程序作为默认选项,并针对GitHub专门使用GitHub提供程序,请执行以下操作:

git config --global credential.helper manager-core
git config --global credential.provider generic
git config --global credential.github.com.provider github

如果您正在使用Atlassian Bitbucket本地服务器,请使用通用提供程序。'bitbucket'提供程序是用于其云服务的。

英文:

On Windows use manager-core and specify the provider. For github we want the github provider, Bitbucket has a bitbucket provider and there is a generic one for normal use.

So to setup for generic as the default and use the github provider for github specifically use:

git config --global credential.helper manager-core
git config --global credential.provider generic
git config --global credential.github.com.provider github

If you are using an Atlassian Bitbucket local server - use generic. The 'bitbucket' provider is for their cloud service.

答案3

得分: 1

With Git 2.39+,GCM(来自Microsoft的Git凭据管理器)不再是“manager-core”,如我在这里解释的

我仅对任何远程服务器(GitHub、GitLab、Bitbucket本地服务器)使用git config --global credential.helper manager

只需确保在执行以下操作时查看您的GitHub令牌(PAT):

printf "host=github.com\nprotocol=https" | git credential-manager get

即使在简单的Windows CMD中(无需bash),只要您的%PATH%包括:

set "GH=%ProgramFiles%\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

不仅允许使用printf%GH%\usr\bin),还允许使用git-credential-manager(-core).exe%GH%\mingw64\bin)。

英文:

With Git 2.39+, the GCM (Git Credential Manager from Microsoft) is no longer "manager-core", as I explained here.

I use only git config --global credential.helper manager for any remote server (GitHub, GitLab, Bitbucket local server)

Just make sure to see your GitHub token (PAT) when doing:

printf "host=github.com\nprotocol=https" | git credential-manager get

That printf command works even in a simple Windows CMD (no bash needed), provided your %PATH% includes:

set "GH=%ProgramFiles%\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

Not only that allows using printf (%GH%\usr\bin), but also git-credential-manager(-core).exe (%GH%\mingw64\bin).

huangapple
  • 本文由 发表于 2023年4月6日 20:34:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949578.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定