3 ms·
Disclosure: I'm the Git Systems PM at GitHub. Opinions are my own and I wasn't directly involved with this effort. GCM Core is a really straightforward way to
by vtbassmatt 5y ago
Disclosure: I'm the Git Systems PM at GitHub. Opinions are my own and I wasn't directly involved with this effort.
GCM Core is a really straightforward way to auth with GitHub and several other Git hosts. It comes with Git for Windows by default, can be installed with `brew` on macOS, and from a .deb on Linux. https://github.com/microsoft/Git-Credential-Manager-Core https://github.com/microsoft/Git-Credential-Manager-Core (it started under the Microsoft banner but is maintained by GitHub employees now).
- gigel82 5y agoGCM still doesn't support multiple users properly, though. Https auth is what I was using for a second GitHub account, so I'm not thrilled about this change. I want to have work and personal GitHub accounts on the same machine and very explicitly choose which account goes to which repo. Too often I have changes going in with the wrong user.name / user.email or account to the point where I paranoidly reauthenticate every time and manually check each clone's .git/config.
- chipotle_coyote 5y agoCan't you still use https with this? You use the personal account token for the specific account to log in as the "password". I've been doing this recently with two GitHub accounts. In my ~/.gitconfig file, I've included [credential "https://github.com"] useHttpPath = true Which means that the first time -- and only the first time -- I try to do something with a GitHub repo that requires authentication, I'll be asked for the username and password (token), and I make sure to use the right one. :) At that point things stay set.
- lentil 5y agoWhile this probably doesn’t completely solve your problem, have you tried using conditional includes in your .gitconfig? I’ve been using that to ensure that anything under ~/work uses my work email for user.email, but anything under ~/projects uses my personal email. It’s quite handy. https://git-scm.com/docs/git-config#_conditional_includes https://git-scm.com/docs/git-config#_conditional_includes
- IshKebab 5y agoOh wow that is genius! I had no idea this existed, thanks!
- batuhanicoz 5y agoI think you can achieve this with an SSH config like Host github-personal HostName github.com IdentityFile ~/.ssh/id_rsa_personal Host github-work HostName github.com IdentityFile ~/.ssh/id_rsa_work Then you can use `github-work` or `github-personal` in the remote URL like `git clone git@github-work:mywork/somerepo.git`. edit: I realized after reading the other comments that I got the problem wrong! This would push the commits from the correct GitHub account but the commits would still have the e-mail from git's config and GitHub would link the account in the committer e-mail.
- judge2020 5y ago> This would push the commits from the correct GitHub account but the commits would still have the e-mail from git's config and GitHub would link the account in the committer e-mail. That seems like a situation where you'd `git config user.email` within your work repo(s) so that it's set locally, not globally. I also think GitHub primarily supports and envisions people using one GH account for work and personal projects.
- vtbassmatt 5y agoWe recently added support for multiple identities but it's not complete (or seemingly documented, oops). I'll take a note to look into fixing and extending it. Edit: but also, GCM Core has nothing to do with the user.email/user.name in .gitconfig. I have a similar problem where I want some commits written with my work email and others with my personal, and I always forget to check it when starting in a new repo. I push them both using a single GitHub identity, though, so your situation has an extra wrinkle.
- 0x0 5y agoYou can use includeIf in your gitconfig to set different email defaults based on directory prefix. So keep your personal projects grouped in a personal directory and you don't have to do anything special for each project
- vtbassmatt 5y agoDon't know if you'll see this now that it's been a few hours, but for anyone trying to work with multiple distinct GitHub identities: GCM Core will read the user part of a URL and use it if provided. There's an "ambient" or "default" user for URLs which don't include a user part, which is the only thing most people use. If I wanted to be really specific to use my `vtbassmatt` identity, I'd write: git clone https://vtbassmatt@github.com/WorkOrg/work-repo.git I manually added the "vtbassmatt@" to tell Git to tell GCM Core that that's who I want to log in as. (Here's where I could tell you about all the ways in which the credential manager system in Git is deficient... I'll spare you, though, and simply say that this is close to the best we can do without a whole other layer of artifice that you probably wouldn't like.)
- gertlex 5y agoI just last night had the idea to put a global git config alias for the `clone` command... Such that it would (1) be preceded by asking me which email I want to use, (2) do the clone, then (3) do `git config user.email bogus@whatever.tld`. Went to bed early rather than finish that, and this just reminded me of it... (offhand, I wouldn't be surprised if my alias has to be something other than `clone`, but no biggie if so)
- cbcoutinho 5y agoAre you open to using a tool like direnv to manage env vars on a directory-wide basis? I used to also suffer from the same paranoia, but direnv has allowed me to take back control regarding directory-specific configuration. You can configure it to set your git user name/email based on your working directory, for example. This is how I keep the separation you mentioned between personal and work on the same machine
- gigel82 5y agoWould something like that exist on Windows? Also, it doesn't seem to solve the problem of multiple accounts; I more or less accepted I need to manually configure user.name and user.email for each clone, but the account is not part of the same config, it looks like it's stored in some other ephemeral place - maybe GCM Core, or some Credential Manager or who knows. I only realize it was using the wrong account when I try to push and get some unauthorized error; by that point, my commit log is polluted with the wrong account so I need to do some gymnastics where I reset the authentication, manually copy over files or unstage to purge the metadata, etc.
- mjcheetham 5y agoGCM Core does support multiple users with GitHub remotes. You have to put the username in the remote URL, for example: https://alice@github.com/owner/repo https://alice@github.com/owner/repo GCM will store credentials for "alice" only. Repositories that have remote URLs with a different "user@" will use different credentials. Remote URLs without a "user@" part at all (like "https://github.com/owner/repo https://github.com/owner/repo") are treated like the "default" user for GitHub.com, rather than a specific one.
- TheRealWatson 5y agoI have gladly forgotten the details by now but last time I developed on Windows GCM was the thing that gave me the most headaches. Our Git was on Azure DevOps (whatever that's called now) not github. Due to reasons we could not use SSH instead.
- deleted 5y ago[deleted]