312

我完全按照这些说明进行操作,包括有关密码缓存的部分。似乎说明是错误的,因为每次git push origin master我收到此错误时:

git: 'credential-cache' is not a git command. See 'get --help'.

...此时我被迫输入我的用户名和密码。这样做之后,我再次看到相同的错误消息,然后是git push.

这是我的 .gitconfig 文件的内容:

[user]
    name = myusername
    email = myusername@myemaildomain.com
[credential]
    helper = cache

需要明确的是,在我安装 Git 并运行 Git Bash 之后,这正是我输入的内容:

git config --global user.name "myusername"
git config --global user.email "myusername@myemaildomain.com"
git config --global credential.helper cache

请帮忙。这太令人沮丧了!

4

19 回答 19

360

我发现的博客中

这个 [git-credential-cache] 不适用于 Windows 系统,因为 git-credential-cache 通过 Unix 套接字进行通信。

用于 Windows 的 Git

由于 msysgit 已被 Git for Windows 取代,因此现在使用Git for Windows是最简单的选择。某些版本的 Git for Windows 安装程序(例如 2.7.4)在安装期间有一个复选框以启用 Git 凭据管理器。这是一个屏幕截图:

Git For Windows 2.7.4 安装向导截图

还在使用 msysgit?对于 msysgit 版本 1.8.1 及更高版本

wincred助手是在 msysgit 1.8.1 中添加的。按如下方式使用它:

git config --global credential.helper wincred

对于早于 1.8.1 的 msysgit 版本

首先,下载git-credential-winstore并将其安装在您的 git bin 目录中。

接下来,确保包含的目录git.cmd在您的 Path 环境变量中。默认目录是64 位系统上的C:\Program Files (x86)\Git\cmd或 32 位系统上的C:\Program Files\Git\cmd。一个简单的测试方法是启动命令提示符并键入git. 如果您没有获得 git 命令列表,则说明设置不正确。

最后,启动命令提示符并键入:

git config --global credential.helper winstore

或者您可以.gitconfig手动编辑文件:

[credential]
    helper = winstore

完成此操作后,您可以通过 Windows 凭据管理器管理您的 git 凭据,您可以通过 Windows 控制面板调出该管理器。

于 2012-08-09T18:06:20.370 回答
72

看起来git现在wincred在 Windows (msysgit) 上提供了开箱即用的功能:

git config --global credential.helper wincred

参考https ://github.com/msysgit/git/commit/e2770979fec968a25ac21e34f9082bc17a71a780

于 2014-03-08T11:12:36.240 回答
35

第一次运行git config --global credential.helper wincred

然后转到:CONTROL PANEL\CREDENTIAL MANAGER\WINDOWS CREDENTIAL\GENERIC CREDENTIAL

然后在Internet or network address: 添加git:https://{username}中单击添加凭据.github.com

User:{姓名}

Password:{密码}

于 2015-12-31T03:18:21.737 回答
27

我在 windows7 上使用 AptanaStudio3 时遇到了这个问题。这帮助了我:

git config --global credential.helper wincred

这里获取的代码

于 2014-02-26T17:16:34.717 回答
19

首先找到您用于 GIT 的版本。

使用这个命令: git --version

如果您有比 1.7.10 更新的版本。

然后只需使用此命令即可。

视窗:

git config --global credential.helper wincred

苹果电脑

git config --global credential.helper osxkeychain

参考

于 2015-11-17T17:48:30.833 回答
16

A similar error is 'credential-wincred' is not a git command

The accepted and popular answers are now out of date...

wincred is for the project git-credential-winstore which is no longer maintained.

It was replaced by Git-Credential-Manager-for-Windows maintained by Microsoft open source.

Download the release as zip file from link above and extract contents to

\cygwin\usr\libexec\git-core

(or \cygwin64\usr\libexec\git-core as it may be)

Then enable it, (by setting the global .gitconfig) - execute:

git config --global credential.helper manager

How to use

No further config is needed.

It works [automatically] when credentials are needed.

For example, when pushing to Azure DevOps, it opens a window and initializes an oauth2 flow to get your token.

ref:

于 2018-11-01T16:45:03.547 回答
10

现在有一种更简单的方法来设置 Git 密码缓存,方法是在 Windows 上双击一个小exe 。git-credential-winstore尽管该项目已从 GitHub 移至http://gitcredentialstore.codeplex.com/ ,但该程序仍基于投票最多的答案。

您可以从此博客文章下载 exe(和 Mac 的二进制文件):https ://github.com/blog/1104-credential-caching-for-wrist-friendly-git-usage

于 2013-05-24T21:47:18.707 回答
10

我通过从特定项目的配置中删除该credential部分来解决此问题:

  • 刚刚输入:git config -e
  • 在编辑器中,我删除了整个部分[credential] helper = cache

这消除了烦人的消息:

git: 'credential-cache' is not a git command. See 'git --help'.

于 2017-12-25T16:05:13.310 回答
7

为了解决这个问题的其他人,我在 Ubuntu 中遇到了同样的问题(即我的密码没有缓存,尽管正确设置了选项并得到了错误git: 'credential-cache' is not a git command.),直到我发现这个功能只是在 Git 1.7.9 及更高版本中可用

在旧版本的 Ubuntu(Natty;我是一个顽固的 Gnome 2 用户)上,repo 中的版本是 git 版本 1.7.4.1。我使用以下 PPA 进行升级: https ://launchpad.net/~git-core/+archive/ppa

于 2012-09-17T16:03:35.620 回答
5

为了其他人有这个问题 - 我来到这里是因为我试图让我如何设置一个新的 github 存储库变得可爱,但是根据设置页面,凭据帮助程序不起作用,除非你克隆一个存储库。

“提示:凭据助手仅在您克隆 HTTPS 存储库 URL 时起作用。如果您改用 SSH 存储库 URL,则使用 SSH 密钥进行身份验证。本指南提供生成和使用 SSH 密钥对的帮助。”

于 2013-10-24T20:51:44.980 回答
4

我意识到我的谈话有点晚了,但我遇到了完全相同的问题在我的 git config 中我有两个条目凭据......</p>

在我的 .gitconfig 文件中

[credential]
helper = cached
[credentials]
helper = wincred

修复:将我的 .gitconfig 文件更改为以下设置

[credential]
helper = wincred
[credentials]
helper = wincred
于 2018-08-19T18:05:35.200 回答
2

另一个有效的解决方法是:

1- 转到控制面板并为 github.com 添加您的凭据,如下所示:

GitHub 的 Windows 凭据

2-转到CMD并输入以下命令:

  • a- cd %localappdata%\Atlassian\SourceTree\git_local\mingw32\bin\
  • b- git.exe 配置 --edit --system
  • c- 更正最后一行:helper = manager
  • d- 通过单击 CTRL+C 然后输入 :wq 然后按 Enter 来保存新的配置文件

更新配置:helper = manager

这对我来说非常有效!

于 2021-12-26T04:05:27.187 回答
1

在较旧的 Ubuntu Linux 系统上:

git config --global credential.helper store
于 2021-10-22T00:41:23.000 回答
1

helper=我的 .gitconfig 的 [credential] 部分中有三个不同的条目,其中一个是空的。删除其他两个并helper=wincred继续为我解决了这个问题。

顺便说一句:我不知道为什么,但我没有立即找到我的 .gitconfig。然后我在 C:\Users\username 中找到了它。

于 2022-01-12T15:53:09.833 回答
1

我真的只是经历了这个!

  1. 下载 Git Credential Manager Core 并安装它:https ://github.com/microsoft/Git-Credential-Manager-Core#download-and-install
  2. 转到Account Settings > EmailsGitHub 上。你应该看到这样的东西: 在此处输入图像描述
  3. 突出显示的电子邮件是系统生成的,以保持您的私人电子邮件的私密性。现在复制它并在下一步中使用它
  4. 配置 git:
 git config --global user.name "yourusername"
 git config --global user.email "1234567+yourgithubusername@users.noreply.github.com"
 git config --global credential.helper cache

现在,您的 git 命令应该可以再次工作了。

小提示:我使用的是 Linux Mint。YMMV

附加说明: Git Credential Manager Core v 2.0.567 在他们的 Debian backage 中有一个错误。请在新版本发布前安装v2.0.474 。

于 2021-11-14T04:25:38.163 回答
0

在 mac 上运行以下命令:

git config --global credential.helper osxkeychain

于 2021-08-03T17:10:30.820 回答
0

在我们的域更改后,我们的 Azure DevOps 存储库也遇到了同样的问题,即从 @xy.com 到 @xyz.com。为了解决这个问题,我们生成了一个新的具有以下权限的个人访问令牌:

代码:读&写 打包:读

然后我们打开 Windows 凭据管理器,添加一个新的通用 Windows 凭据,其中包含以下详细信息:

Internet 或网络地址: “git:{ projectname }@dev.azure.com/{ projectname }” - 或者,您应该在此处使用您的 git 存储库名称。
用户名: “个人访问令牌”
密码: {生成的个人访问令牌}

之后我们所有的 git 操作都重新开始工作了。希望这对其他人有帮助!

于 2020-01-10T08:29:05.040 回答
0

当前与 Git for Windows(2.32,2021 年第 2 季度)打包的凭证助手是

 git config credential.helper
 manager-core

 where git-credential-manager-core
 C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager-core.exe

这是在 GCM-core(Git Credential Manager Core)之后:microsoft/Git-Credential-Manager-Core/

Git Credential Manager Core (GCM Core) 是基于 .NET 构建的安全 Git 凭证助手,可在 Windows 和 macOS 上运行。Linux 支持处于早期预览阶段。

与 Git 的内置凭证助手(Windows:wincred,macOS:osxkeychain,Linux:gnome-keyring)相比,GCM Core 为Azure DevOps提供单因素身份验证支持、Azure DevOps Server(以前称为 Team Foundation Server)、GitHub 和 Bitbucket。

Git Credential Manager Core (GCM Core) 取代了基于 .NET Framework 的Git Credential Manager for Windows (GCM)和基于 Java 的Git Credential Manager for Mac 和 Linux (Java GCM),在所有平台上提供一致的身份验证体验。


随着 Git 2.34(2021 年第四季度),Unix 套接字开始考虑用于 Windows 的 Git:

请参阅Carlo Marcelo Arenas Belón ( ) 的提交 bb390b1提交 245670c提交 0fdcfa2(2021 年 9 月 14 日(由Junio C Hamano 合并 -- --提交 c2e7990中,2021 年 9 月 23 日)carenas
gitster

git-compat-util: 在 windows 中包含 unix 套接字的声明

签字人:Carlo Marcelo Arenas Belón

自 Windows 10 版本 1803 和 Windows Server 2019 起可用。

NO_UNIX_SOCKETS仍然是 Windows 构建的默认设置,因为它们需要保持与 Windows 7 之前的版本的向后兼容性,但允许在其他情况下包含标头。

于 2021-08-13T07:35:38.220 回答
0

我最初的答案结果证明即使对我自己也不是很有用,所以我仔细研究了一下,发现了一个 hack(虽然有点复杂)。

所以,我git在 MSYS2 下使用,并且我想使用credential-cache, 来暂时记住我的密码(而且我还没有看到这样的用例wincred或其他适用于 Windows 的方法)。

基本上,这需要在https://github.com/git/git/blob/55144cc/builtin/credential-cache--daemon.c#L239中进行破解- 而不是die-ing 在该行中,我们想继续.

所以,首先,我们要git在 MSYS2 下构建。

因此,我们需要构建git在 MSYS2 中使用的实际。首先,检查版本:

$ git --version
git version 2.33.0
$ pacman -Ss git | grep installed # msys/git 2.33.0-1 (VCS) [installed]

然后,按照https://www.msys2.org/wiki/Creating-Packages/,我们可以这样做:

$ git clone "https://github.com/msys2/MSYS2-packages"
$ cd MSYS2-packages/
$ cd git
$ makepkg -sCLf
==> Making package: git 2.33.0-1 (Thu, Sep 23, 2021 12:47:33 PM)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Installing missing dependencies...
...
make[1]: Entering directory '/c/src/MSYS2-packages/git/src/git-2.33.0'
make[1]: 'GIT-VERSION-FILE' is up to date.
make[1]: Leaving directory '/c/src/MSYS2-packages/git/src/git-2.33.0'
sed -e '1s|#!.*/sh|#!/bin/sh|' git-subtree.sh >git-subtree
chmod +x git-subtree
make: Leaving directory '/c/src/MSYS2-packages/git/src/git-2.33.0/contrib/subtree'
==> Starting check()...

注意这里:

  • 这个构建过程首先以 ASCIIDOC/XMLTO 部分结束,这在我的机器上需要半小时
  • 然后它会在一个需要更长时间的部分结束*** prove ***,但可以用 Ctrl-C 中断,并且构建的可执行文件不会被删除。

所以,现在我们想在源代码中做一个 hack;笔记:

  • 如果我们在源代码中进行hack,我们不想使用makepkg -sCLf,因为这将删除源目录(以及所有构建的 .exe 工件),然后在构建之前重建它

因此,我们使用 hack 进行破解sed,然后构建:

$ sed -i 's/die(_(permissions_advice), dir);/fprintf(stderr, "Permissions on cached credentials socket directory %s are too loose, but HACK: going on\\n", dir);/' ./src/git-2.33.0/builtin/credential-cache--daemon.c
$ (cd src/git-2.33.0/; make)
    CC builtin/credential-cache--daemon.o
    LINK git.exe
...
    SUBDIR templates

在这一点上,请注意,黑客最终至少包含三个可执行文件,可以通过以下方式确认:

$ grep -ao ....HACK........ ./src/git-2.33.0/git-credential-cache--daemon.exe
$ grep -ao ....HACK........ ./src/git-2.33.0/git-credential-cache.exe
$ grep -ao ....HACK........ ./src/git-2.33.0/git.exe

...在替换所有三个之后,我只能让它工作:

# backup the original files:

$ mv /usr/lib/git-core/git-credential-cache--daemon.exe /usr/lib/git-core/__git-credential-cache--daemon_orig.exe
$ mv -v /usr/lib/git-core/git-credential-cache.exe /usr/lib/git-core/__git-credential-cache__orig.exe
$ mv -v /usr/bin/git.exe /usr/bin/__git_orig.exe
$ mv -v /usr/lib/git-core/git.exe /usr/lib/git-core/__git_orig.exe

# copy over the hacked files:

cp -v ./src/git-2.33.0/git-credential-cache--daemon.exe /usr/lib/git-core/
cp -v ./src/git-2.33.0/git-credential-cache.exe /usr/lib/git-core/
cp -v ./src/git-2.33.0/git.exe /usr/bin/
cp -v ./src/git-2.33.0/git.exe /usr/lib/git-core/

在这一点上,credential-cache我也开始在 MSYS2 上工作(在有限的时间内缓存密码);只是它在启动时转储了被黑的行:

$ git pull
Password for 'https://user@git.mysite.com':
Permissions on cached credentials socket directory /home/user/.cache/git/credential are too loose, but HACK: going on
Already up to date.

# second pull, password is cached
$ git pull
Already up to date.

有点棘手,但似乎有效。

PS:一个棘手的事情是,我最初die只用printfto替换stdout,但一直失败;事实证明,stdout它用于进程间通信,并且要成功,显然答案ok\0stdout三个字节;所以解决方案是打印通知stderr


(原答案):

虽然没有完全按照要求回答问题,但这是我能找到的最合适的问题,将其记录为答案:

git在Windows 10的MSYS2下使用,目前有以下版本:

$ git --version
git version 2.32.0

我通常只想让 git 在有限的时间内(可能 10 分钟左右)缓存我的密码,然后忘记它;而且我还没有看到wincred在该用例中使用或其他特定于 Windows 的凭据管理器。

话虽这么说,但对我来说有一个“简单的解决方法”——基本上,凭证管理器第一次运行就可以了;只有在随后的使用中,我才得到:

$ git push
Password for 'http://user@githost.example.com':
fatal: The permissions on your socket directory are too loose; other
users may be able to read your cached credentials. Consider running:

        chmod 0700 /home/user/.cache/git/credential
fatal: cache daemon did not start:
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
...

因此,基本上,解决方法是删除credential目录 - 此后,凭据缓存管理器就像第一次一样运行,并在有限的时间内缓存密码 - 就像我想要的那样:

$ rm -rf ~/.cache/git/credential


# note below, the very first pull still asks for a password:

$ git pull
Password for 'http://user@githost.example.com':
Already up to date.

# ... but the second pull does not, it uses credentials cache

$ git pull
Already up to date.

对我来说已经足够了,我猜:)

编辑:不是真的,我在此之后立即体验到,如果您尝试拉入另一个选项卡,错误就会返回。

于 2021-08-13T07:09:51.380 回答