Git:强制用户和密码提示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14643308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:24:25  来源:igfitidea点击:

Git: force user and password prompt

gitgithub

提问by tompave

I recently updated my local Git installation to 1.8.1from 1.8.0.1.

我最近将本地 Git 安装更新为1.8.1from 1.8.0.1.

I'm noticing that, when I work on GitHub, it doesn't prompt me for username and password on push anymore.

我注意到,当我在 GitHub 上工作时,它不再提示我在推送时输入用户名和密码。

This troubles me, as I see having to type user and password every time as a good security measure. (what if someone else uses my computer?)

这让我很困扰,因为我认为每次都必须输入用户名和密码作为一种很好的安全措施。(如果其他人使用我的电脑怎么办?)

I checked the following:

我检查了以下内容:

  • 1.8.0.1on another computer still asks for username and password.
  • my account on github still enforces private/security controls.
  • I am using https remote references, rather than ssh.
  • For good measure, I checked in my ~/.sshfonder. Nothing wrong there.
  • I'm notstoring the login details in ~/.gitconfigor individual <proj>/.git/configfiles.
  • I'm also notstoring anything github-related in ~/.netrc.
  • I created a new dummy archive: still doesn't prompt me for login.
  • 1.8.0.1在另一台计算机上仍然要求输入用户名和密码。
  • 我在 github 上的帐户仍然强制执行私有/安全控制。
  • 我使用的是 https 远程引用,而不是 ssh。
  • 为了更好的衡量,我检查了我的~/.ssh情人。没有错。
  • 没有将登录详细信息存储在~/.gitconfig单个<proj>/.git/config文件中。
  • 我也没有~/.netrc.
  • 我创建了一个新的虚拟存档:仍然不提示我登录。

I couldn't find anything in the git release notes archive.

我在 git发行说明存档中找不到任何内容。

Does anyone know if this is a new git behaviour? How do I restore the prompt?

有谁知道这是否是一种新的 git 行为?如何恢复提示?

采纳答案by VonC

With git config -l, I now see I have a credential.helper=osxkeychainoption

有了git config -l,我现在看到我有一个credential.helper=osxkeychain选择

That means the credential helper(initially introduced in 1.7.10) is now in effect, and will cache automatically the password for accessing a remote repository over HTTP.
(as in "GIT: Any way to set default login credentials?")

这意味着凭证助手(最初在 1.7.10 中引入)现已生效,并将自动缓存用于通过 HTTP 访问远程存储库的密码。
(如“ GIT:有什么方法可以设置默认登录凭据?”)

You can disable that option entirely, or only for a single repo.

您可以完全禁用该选项,也可以禁用单个 repo

回答by sapy

Add a -v flag with your git command . e.g. git pull -v

使用 git 命令添加 -v 标志。例如 git pull -v

v stands for verify .

v 代表验证。

回答by pixel

This is most likely because you have multiple accounts, like one private, one for work with GitHub.

这很可能是因为您有多个帐户,例如一个私人帐户,一个用于使用 GitHub。

SOLUTION On Windows, go to Start > Credentials Manager > Windows Credentials and remove GitHub creds, then try pulling or pushing again and you will be prompted to relogin into GitHub

解决方案 在 Windows 上,转到 Start > Credentials Manager > Windows Credentials 并删除 GitHub 凭据,然后再次尝试拉或推,系统将提示您重新登录到 GitHub

SOLUTION OnMac, issue following on terminal:

解决方案在 Mac 上,在终端上发出以下问题:

git remote set-url origin https://[email protected]/username/repo-name.git

by replacing 'username' with your GitHub username in both places and providing your GitHub repo name.

通过在两个地方用您的 GitHub 用户名替换“用户名”并提供您的 GitHub 存储库名称。

回答by Mike Wise

None of those worked for me. I was trying to clone a directory from a private git server and entered my credentials false and then it wouldn't let me try different credentials on subsequent tries, it just errored out immediately with an authentication error.

这些都不适合我。我试图从私有 git 服务器克隆一个目录并输入我的凭据 false 然后它不会让我在后续尝试中尝试不同的凭据,它只是立即出错并出现身份验证错误。

What did work was specifying the user name (mike-wise)in the url like this:

有效的是mike-wise在 url 中指定用户名 ( ),如下所示:

   git clone https://[email protected]/someuser/somerepo.git

回答by Afshin Mehrabani

Since the question was labeled with Github, adding another remote like https_originand add the httpsconnection can force you always to enter the password:

由于问题标有Github,因此添加另一个遥控器https_origin并添加https连接可以强制您始终输入密码:

git remote add https_origin https://github.com/.../...