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

hot*_*oup 5 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
Run Code Online (Sandbox Code Playgroud)

这是该组织下的私人仓库。奇怪的是它甚至没有提示我输入用户名或密码,这表明我以某种方式将本地 git 配置为自动发送与有效的 org/repo 用户名不匹配的用户名,因此它自动让我失败。

我有几个 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
Run Code Online (Sandbox Code Playgroud)

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

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

更新

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

$ git credential-osxkeychain
usage: git credential-osxkeychain <get|store|erase>
Run Code Online (Sandbox Code Playgroud)

所以我然后运行以下命令(以禁用助手):

$ 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
Run Code Online (Sandbox Code Playgroud)

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

Rob*_*ier 7

在 URL 中传递用户名:

git clone https://username@github.com/<THEIR_ORG>/<THEIR_REPO>.git
Run Code Online (Sandbox Code Playgroud)