I would like to be able to use 2 or more github accounts on one computer without the need to change the url or switching accounts in the gh cli. This should be for all git commands including the clone. I’d be happy to use multiple .git_config files and link them by directory or by remote url.
Here is what I have currently but appears to not work as intended. Also I am using a mac if that matters.
~/.git_config
[user]
name = My Name
email = [email protected]
[credential]
username = my-personal-github-user
[includeIf "hasconfig:remote.*.url:https://github.com/WorkOrg/*"]
path = ~/.git_config_work_org
~/.git_config_work_org
[user]
email = [email protected]
[credential]
username = work-github-username
helper = !gh auth git-credential
If I read the documentation correctly for both git and gh cli, this should be all that is needed to give me the desired results. But it doesn’t appear to work completely.
In the gh cli, I can see that the active account for credentials. If the personal github account is active, I can not clone a repo. When I change to the work account I can then clone the repo as expected. However the idea is that this should be seamless so I can just checkout a repo without the effort of having to think about which credential is active and is it the correct one and change it if required.
When looking at the git trace output I can see that the username used is whatever account is active in the gh cli. Which explains the behaviour above, but completely defeats the purpose of this.
The questions; Is there something I am missing in the current config? Is what I want possible?
https://git-scm.com/docs/git-config#Documentation/git-config.txt-codehasconfigremoteurlcode
Ideally I would have one of these custom includes for every account that requires specific credentials and then my personal account as the default catch all for everything else.