[英]How to force git to prompt me for username + password on clone request
我正在加入一個新團隊,並已成為 GitHub 組織的成員,該組織(至少在 web UI 中)使我可以完全讀取他們的存儲庫。 所以我嘗試在本地克隆一個倉庫:
git clone https://github.com/<THEIR_ORG>/<THEIR_REPO>.git
(where the clone URL there is pasted from my clipboard, and I've verified several times it is correct). 這就是我所看到的:$ 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 配置為自動發送與有效的 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
此外,我必須為此組織啟用 2FA,但我已經生成了我的個人訪問令牌並將使用(一旦提示這樣做)作為密碼,而不是我的正常 GH 密碼。
我想我需要做的就是強制git 提示我輸入憑據,然后我可以發送它們並完成克隆請求。
我在想 OSX Keychain 憑證助手可能是這里的一個因素,所以我嘗試運行:
$ 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
我重新啟動終端並再次嘗試相同的克隆......但沒有骰子。
在 URL 中傳遞用戶名:
git clone https://username@github.com/<THEIR_ORG>/<THEIR_REPO>.git
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.