在推送到 git 存储库时,如何强制使用用户和密码提示符?

我最近将我的本地 Git 安装从 1.8.0.1更新为 1.8.1

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

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

我查了下面的内容:

  • 另一台计算机上的 1.8.0.1仍然要求输入用户名和密码。
  • 我在 Github 上的账户仍然实行私人/安全控制。
  • 我使用的是 https 远程引用,而不是 ssh。
  • 为了保险起见,我检查了我的 ~/.ssh爱好者,没什么问题。
  • 我的 没有存储在 ~/.gitconfig或个人的 <proj>/.git/config文件登录细节。
  • 我还在 ~/.netrc中存储任何与 github 相关的内容。
  • 我创建了一个新的虚拟存档: 仍然没有提示我登录。

我在车里找不到任何东西。

有人知道这是否是一个新的 git 行为吗? 我如何恢复提示符?

192208 次浏览

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

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?")

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

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

v stands for verify .

Since the question was labeled with Github, adding another remote like https_origin and add the https connection can force you always to enter the password:

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

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.

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

   git clone https://mike-wise@collab.somewhere.net/someuser/somerepo.git

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

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

SOLUTION OnMac, issue following on terminal:

git remote set-url origin https://username@github.com/username/repo-name.git

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

Addition to third answer: If you're using non-english Windows, you can find "Credentials Manager" through "Control panel" > "User Accounts" > "Credentials Manager"

enter image description here

The easiest way to get around the dumb github restriction is making an api token under developer in your profile settings. Then you can change your repo url to be @url