-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple accounts #3278
Conversation
Now hosts.yml supports user/organization part in a host section name that allows to tune credentials based on a github user or an organization instead of just a host name. Example: ```yaml github.com: user: personal-account oauth_token: personal-token github.com/acme: user: work-account oauth_token: work-token ``` So when `gh` is running in the directory related to any repository of _acme_ organization, it will use _work-account_. In all other cases _personal-account_ will be used. A repository is treated as related to _acme_ organization if git config property `remote.origin.url` matches one of two forms: * `git@github.com:acme/repo.git` * `https://github.com/acme/repo.git`
Will there be any way to indicate who is currently logged on in |
Do you mean |
Yes
|
@dmitry-at-hyla Thank you for this feature! I realize that implementing it might have been tricky since our authentication layer wasn't really built for this kind of on-the-fly switching between the accounts. We looked at this, but unfortunately we won't pull it at this time since we haven't yet decided if we want switching between multiple users and how it should work. I do not think that username switching will be based on who owns the repository you're currently in, since that leaves the question of which GitHub user should be used for all other repositories. I think that, ultimately, we will have to extend our configuration system with some finer-grained controls. Anyway, since this is something that we will probably have to do ourselves, we've labeled the original issue However, I liked seeing your changeset because it illustrates roughly how much work will be involved in making this feature happen. It might help someone implement this in the future. |
Well, it's easy to implement. Unfortunately, this PR is rejected. However, I can do this in my fork. Are you interested in that? |
@mislav Duly noted. JFYI: username switching is not based on the owner of the repo, but the user bound to the repo pattern defined in hosts.yml. Anyway, I got your point, there's going to be a lot of work to redesign hosts.yml-related code. Thank you! |
@dmitry-at-hyla I was just checking this PR because it seemed like it passed the checks and would likely be merged. |
Now hosts.yml supports user/organization part in a host section name that allows to tune credentials based on a github user or an organization instead of just a host name.
Example:
So when
gh
is running in the directory related to any repository of acme organization, it will use work-account. In all other cases personal-account will be used. A repository is treated as related to acme organization if git config propertyremote.origin.url
matches one of two forms:git@github.com:acme/repo.git
https://github.com/acme/repo.git
Refer #326