4

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.

hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
  • Does this answer your question? [How do I provide a username and password when running "git clone git@remote.git"?](https://stackoverflow.com/questions/10054318/how-do-i-provide-a-username-and-password-when-running-git-clone-gitremote-git) – mfaani Jun 05 '20 at 17:53
  • It's also worth noting that GitHub encourages using tokens. See [here](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) – mfaani Jun 05 '20 at 18:05

1 Answers1

5

Pass the username in the URL:

git clone https://username@github.com/<THEIR_ORG>/<THEIR_REPO>.git
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • That works!!!! Any chance I could be so bold as to ask for an explanation as to why git wasn't prompting me for the username?! Thank you so much! – hotmeatballsoup Jun 05 '20 at 17:47
  • GitHub returns 404 (not found) when you're unauthorized, so you can't try to find private repos (I assume that's why). It doesn't return a 401 (not authorized), which would tell git to ask for credentials. – Rob Napier Jun 05 '20 at 17:57