How to force git to prompt me for username + password on clone request

Viewed 2423

I am being onboarded to a new team and have been made a member of their organization in GitHub, which (at least in the web UI) gives me full read access to their repos. So I try to clone one repo locally:

  1. I go to the repo in GitHub and click the "Clone or download" link and select "Clone with HTTPS" (which is what I want)
  2. I copy the clone URL to my clipboard
  3. From a terminal I run 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). This is what I see:
$ 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

This is a private repo under the organization. The curious thing is its not even prompting me for a username or password, which indicates to me that somehow I have my local git configured to automatically send a username which doesn't match a valid org/repo username and so its failing me automatically.

I have several GitHub accounts (for work + play) and I've used this laptop for all of them over the past several years.

So I ask: why is git not prompting me for a username/password? How can I force it to prompt me?

For the record I check my ~/.gitconfig file and the contents are:

[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

Also I had to enable 2FA for this organization, but I have generated my Personal Access Token and will use that (once prompted to do so) as the password instead of my normal GH password.

I think all I need to do is to force git to prompt me for credentials, and then I can send them and complete the clone request.

Update

I was thinking the OSX Keychain credential helper might be a factor here, so I tried running:

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

So I then run the following commands (to disable the helper):

$ 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

I restart the terminal and attempt the same clone again...but no dice.

1 Answers

Pass the username in the URL:

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