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?
-
1Are you using your GitHub password or a token of some sort?bk2204– bk22042019年05月04日 14:21:09 +00:00Commented May 4, 2019 at 14:21
-
password. not token.xiaodai– xiaodai2019年06月18日 05:32:07 +00:00Commented Jun 18, 2019 at 5:32
2 Answers 2
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
Comments
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
.