Most common way people solve this issue is to: git config --global credential.useHttpPath true
- and have different user/pass record in credential storage for every repo. But if you have tons of repos, this can pollute credential store quite fast, making it not really that nice of a solution.
You would end up with records like:
git:https://PersonalAccessToken@github.com/YourUsername/YourRepo1.git
git:https://PersonalAccessToken@github.com/YourUsername/YourRepo2.git
git:https://PersonalAccessToken@github.com/YourUsername/YourRepo3.git
git:https://github.com/YourUsername/YourRepo1.git
git:https://github.com/YourUsername/YourRepo2.git
git:https://github.com/YourUsername/YourRepo3.git
The way I prefer to solve this issue is to use credential.namespace git config option. Idea is to create different namespaces for your different accounts, so that they don't clash in your system credential manager.
For example (using github.com as example url), you can decide one of those accounts is your main and set it up in global git config:
git config --global credential.namespace "MainAccount"
git credential approve
url=https://github.com
username=YourMainAccUsername
password=YourMainAccPasswordOrToken
<Enter>
and then enter repo where you want to log in with different credentials and set it up locally:
cd path/to/other/repo
git config credential.namespace "OtherAccount"
git credential approve
url=https://github.com
username=YourOtherAccUsername
password=YourOtherAccPasswordOrToken
<Enter>
And you can verify in your credential manager, you should have two new records:
MainAccount:https://github.com/
OtherAccount:https://github.com/
And you can verify in command prompt what credentials will be sent to git server:
git credential fill
url=https://github.com
<Enter>