如何在克隆请求中强制git提示我输入用户名和密码

时间:2020-06-05 16:44:17

标签: git macos github

我已经加入了一个新团队,并已成为GitHub中其组织的成员,该组织(至少在Web UI中)使我可以完全读取其存储库。因此,我尝试在本地克隆一个存储库:

  1. 我转到GitHub中的存储库,然后单击“ 克隆或下载”链接,然后选择“ 使用HTTPS克隆”(这就是我想要的)
  2. 我将克隆URL复制到剪贴板中
  3. 在终端上,我运行git clone https://github.com/<THEIR_ORG>/<THEIR_REPO>.git(将克隆URL粘贴到剪贴板中,并且已多次验证它是正确的)。这是我看到的:
$ git clone https://github.com/<THEIR_ORG>/<THEIR_REPO>.git
Cloning into '<THEIR_REPO>'...
remote: Repository not found.
fatal: repository 'https://github.com/<THEIR_ORG>/<THEIR_REPO>.git/' not found

这是该组织下的私人存储库。奇怪的是,它甚至没有提示我输入用户名或密码,这向我表明不知何故我已将本地git配置为自动发送与有效的组织/回购用户名不匹配的用户名所以它自动使我失败。

我有几个GitHub帐户(用于工作和娱乐),并且在过去几年中,我一直在使用这台笔记本电脑。

所以我问:为什么git不提示我输入用户名/密码?如何强制它提示我?

为了记录,我检查了我的~/.gitconfig文件,其内容是:

[core]
        excludesfile = /Users/myuser/.gitignore_global
[difftool "sourcetree"]
        cmd = opendiff \"$LOCAL\" \"$REMOTE\"
        path =
[mergetool "sourcetree"]
        cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
        trustExitCode = true
[user]
        name = My Name
        email = <MY_WORK_EMAIL_ASSOCIATED_WITH_THE_CORRECT_GH_ACCOUNT>
        username = <MY_WORK_USERNAME_ASSOCIATED_WITH_THE_SAME_GH_ACCOUNT>
        signingkey = <MY_GPG_SIGNING_KEY>
[commit]
        template = /Users/myuser/.stCommitMsg
        gpgsign = true

我还必须为此组织启用2FA,但是我已经生成了我的个人访问令牌,并且将使用它(一旦系统提示这样做)作为密码,而不是我的常规GH密码。

我认为我要做的就是强制 git提示我输入凭据,然后我可以发送它们并完成克隆请求。

更新

我当时认为OSX钥匙串凭证助手 可能是其中的一个因素,所以我尝试运行:

$ git credential-osxkeychain
usage: git credential-osxkeychain <get|store|erase>

因此,我然后运行以下命令(以禁用帮助程序):

$ git config --local --unset credential.helper
fatal: --local can only be used inside a git repository

$ git config --global --unset credential.helper

$ git config --system --unset credential.helper
error: could not lock config file /etc/gitconfig: Permission denied

$ sudo git config --system --unset credential.helper

我重新启动终端,然后再次尝试相同的克隆...但没有骰子。

1 个答案:

答案 0 :(得分:3)

在URL中传递用户名:

git clone https://username@github.com/<THEIR_ORG>/<THEIR_REPO>.git