7

I have a GitHub handle that I've used for years, however, after joining a new company, they required that I register a new GitHub account under the company email address. Now I can't clone the private repo because the user.name is set as my normal GitHub handle.

I read on this page that I can add my username before the URL like git clone https://[email protected]/companyname/repo-name.git.

However, I get the error

Cloning into 'repo-name'...
remote: Repository not found.
fatal: repository 'https://[email protected]/companyname/repo-name.git/' not found

How do I clone the company's repo using a different user name?

asked May 4, 2019 at 12:34
2
  • 1
    Are you using your GitHub password or a token of some sort? Commented May 4, 2019 at 14:21
  • password. not token. Commented Jun 18, 2019 at 5:32

2 Answers 2

4

Based on your example output, git is not asking you for a password. It looks like:

  • Your credentials are cached
  • The credentials are for your personal account, not your new company account

You have correctly added your new username to the URL. But by default, git only cares about the host when applying cached credentials.

You can use the useHttpPath option of gitcredentials to tell git to consider the URL path, as well. This will allow you to use different accounts with different repositories.

https://git-scm.com/docs/gitcredentials.html#Documentation/gitcredentials.txt-useHttpPath

useHttpPath

By default, Git does not consider the "path" component of an http URL to be worth matching via external helpers. This means that a credential stored for https://example.com/foo.git will also be used for https://example.com/bar.git. If you do want to distinguish these cases, set this option to true.

Configure this by running the following command:

git config --global credential.https://github.com.useHttpPath true
answered May 4, 2019 at 16:30
Sign up to request clarification or add additional context in comments.

Comments

1

The config user.name has nothing to do with authentication.

Do check you git config credential.helper setting.
If set, that means your credentials might be cached: you would need to remove them or, better, use an SSH URL (one where you can set a different private key for different URL)

If this is not a cached issue, simply check that usernamenew does have access to github.com/companyname/repo-name.git.

answered May 4, 2019 at 16:29

2 Comments

git config credential.helper returns nothing
@xiaodai Then check if /usernamenew has actually access to github.com/companyname/repo-name.git

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.