-
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
Allow multiple account credentials #326
Comments
Is there currently a way to work around this by removing the current authentication? I can't seem to find it. Reinstalling seems to work, but it's very cumbersome. |
@eXamadeus GitHub CLI currently has no mechanism for switching between multiple GitHub accounts and I don't really have a workaround to suggest for you at this moment, sorry. The only approach I could imagine, but would not recommend to anyone, would be to authenticate with 1st account, save a copy of Since this solution involves using SSH for git protocol, make sure both configuration files include the |
If we can add two entries or as many entries on every
If the PS: I have not gone through the codebase. These are my assumptions. |
Searched and landed here. This feature would help people with two or more accounts (personal/business/others) and use both of them every day (swapping the config file would be too much for them). |
It's a bit hacky, but I solved this so that I could evaluate if I want to actually use this cli by using the token auth capabilities, putting this into my dotfiles.
|
@fdm1 Which config file did you fill that in? |
Just in my bash dotfiles |
Now that #2179 has been merged, perhaps it will be less effort to implement this feature? Would be nice to have something like how
editNow that I think about it some more, can |
Since #2444 has been merged, as an alternative solution, set the environment variable |
I just implemented simple multi-account support based on the So having hosts.yml as github.com:
user: personal-account
oauth_token: personal-token
github.com/acme:
user: work-account
oauth_token: work-token we use work credentials for all acme repositories and personal credentials for everything else.
|
Maybe this is a workaround if u wanna use multi credentials for a specific command. such as /usr/local/pr2 #!/usr/bin/python3
import subprocess
import json
import os
import re
with open(os.path.expanduser('~/.pr-config.json')) as f:
configs = json.load(f)
command = 'gh pr view --web'
remote_url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).strip().decode()
for pattern, config in configs.items():
is_match = re.match(pattern, remote_url)
if is_match:
os.system(
f'GH_HOST={config["host"]} GH_ENTERPRISE_TOKEN={config["token"]} {command}'
)
break ~/.pr-config.json {
"git@enterprise.com": {
"host": "enterprise.com",
"token": ""
},
"git@enterprise1.com": {
"host": "enterprise1.com",
"token": ""
}
} |
I am able to have multiple accounts signed in and that is nice, but one thing that I am trying to do is when I am creating a repository I would like to select my account. Doing something like |
I've created a bash wrapper script for |
¡Hello! After having read everything, I believe it'd be more robust not to second-guess anything, and mark the user to use via Git's own configuration mechanism. From the original submission, the work config would be expanded to specify the username to use for the server in question:
That way, we'd leverage the $ git config --get gh.github.com.user
workuser (The hosts.yml format would have to be adjusted to be able to take multiple user stanzas, of course. A bit, but not quite, like #326 (comment).) Edited to add: sadly, it would not work for things like Replying now to #326 (comment):
I'm not sure that's a viable approach, since some users may not alter |
I strongly recommend using direnv in conjunction with |
This is by far the easiest solution. If you don't like/cannot use direnv, you can still manually prefix
|
This comment was marked as spam.
This comment was marked as spam.
I need to be able to set GH_CONFIG_DIR to use GH CLI features in non-personal accounts. When the [GH CLI](cli/cli#326) supports multiple profiles I may disable direnv again.
|
It is worth mentioning that:
I think the last part missing is the multi-account support in the |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
following Multi-account support on GitHub.com accouterments. is gh going to add support for multi-account? |
@electriquo : To give an explicit answer: yes As you might see on this issue in the timeline, @williammartin and @samcoe have been working through the implications of multiple account and how this affects the authentication schema and the product experience. |
To give a more nuanced answer: mostly, but it depends exactly what you mean As @andyfeller mentioned above we are very actively exploring native support for being able to log into multiple accounts on a single host, and switch between them manually. In #8281 we are laying the ground work for the configuration schema and keyring migrations that need to occur to support this whilst providing backwards and a reasonable amount of forwards compatibility. After we feel comfortable with this, we will look to ship a UX focused around something like Explicitly out of scope for this tranche of work is automatic account switching based on some criteria (be that Cheers ✌ |
For Christmas, I'm asking Santa for |
Having read through many issues on the topic now, I'm wondering if a proposal like this: #7081 (separating out the protocol + not hardcoding it into the host URL) couldn't be extended to also include Having to repeatedly (re)set and look up environment variables like I haven't really dug into the code (not a Go person) but considering |
Hi @keikoro, I'm not really following your comment sorry. Can you outline a bit more how you would expect this to work? In particular, how you would expect this to impact a scenario like: "I want to trigger workflow runs in private repositories that I only have access to in different accounts". Cheers! |
Hey folks, especially @ConnorIngold 🎅 , As we're heading towards releasing the first piece of multi-account functionality, I just wanted to share the multi-account-beta-20231202 branch which contains most of the changes we'd like to ship. Specifically, the UX changes are in:
The consequence of this is that you should be able to get tokens for multiple accounts and switch between those tokens easily with We know there are many more features requested throughout this issue (e.g. automatic switching, automatic user and email git configuration), and there are plenty of other quality of life (get token with If you're interested in playing around with this branch, read on... Testing out multi accountThe multi-account-beta-20231202 branch can be built from source and can be used at outlined above. Note that there is not yet an account switching interstitial page in the authentication flow with GitHub, so at the point you open your browser, you'll want to have used the browser based account switcher to be logged in as the user you intend to authenticate with in the CLI. The main challenge in this work was that the If you do run into issues with any of this, particularly around the schema migration, we'd love to know. Please leave feedback relating to this test branch in #8403, to avoid adding more noise to this issue. Cheers! |
@gabe565 : wanted to make an intentional effort to invite you to test this beta feature and share your insights given https://github.com/gabe565/gh-profile 🙇 thank you again for supporting our community's needs for so long ❤ |
We've shipped the initial work described above in v2.40.0. Please read the release notes and the linked technical document for more details about what is in and out of scope and what the sharp edges might be. Please leave any feedback on the release discussion. As described in the technical document, we know there are plenty of things discussed in this issue that were not in scope for this release, so I will be leaving this issue open. |
@williammartin , I was reviewing my GitHub CLI configuration and you've just delighted me with the support for multiple logins. I'm pleased to see that you are working on the extra features to make this complete. I'm now subscribed to the issue to stay up to date. |
cli/cli • ***@***.***
…On Sat, Mar 9, 2024, 2:43 PM Iain Samuel McLean Elder < ***@***.***> wrote:
@williammartin <https://github.com/williammartin> , I was reviewing my
GitHub CLI configuration and you've just delighted me with the support for
multiple logins. I'm pleased to see that you are working on the extra
features to make this complete. I'm now subscribed to the issue to stay up
to date.
—
Reply to this email directly, view it on GitHub
<#326 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APTHBILJ2OYLCCN4RBI5GILYXNQ63AVCNFSM4KRIJKRKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJYGY4TKOJTGQ2A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
to enable multiple user accounts cli/cli#326
This comment was marked as spam.
This comment was marked as spam.
It's great to read that there is progress being made on this request. Addressing one consistent comment:
I agree that there shouldn't be complex logic that determines which account to use, but if there is support for Similarly, is the current scope to only support controlling the globally authenticated user (or "context", if using k8s parlance)? It would be really nice to not do that, and instead run with a UX that matches the other Github apps, where most users are assumed to have a "default" username that they use for most things, and N other usernames used for work/private uses. |
@cornfeedhobo thanks for the feedback. It would be great if you could create an Cheers! |
Describe the feature or problem you’d like to solve
I have two accounts on github each with access to a different set of private repositories. Currently I use a combination of git's
[IncludeIf ...]
config and a custom config which overrides the SSH private key I use for certain repositories. E.g.:In
~/.gitconfig
:and in
~/work/.gitconfig
:It will be great if the credentials for
gh
can also be configured per repository as well.Proposed solution
There are a bunch of options I can think of:
gh
config by a file in a local clone's.git
directorygh
config which defines which repos/orgs should use which credential. E.g.How will it benefit CLI and its users?
It will allow Github users with multiple accounts of varying access to seamlessly work on different repositories.
The text was updated successfully, but these errors were encountered: