5 ms·
Git with Multiple Email Addresses
- angrais 4y agoI similarly have multiple git accounts and repos. When I clone a repo i do so via SSH. When I am in the folder of one repo (say a GitHub.com repo) then the ssh account that cloned the repo is used. I'm not near my laptop, but it's two lines of code in the SSH config files and that's it. Does anyone follow a similar pattern?
- thewavelength 4y agoPlease provide these two lines, I'd love to utilize the same pattern in the future :)
- rgoulter 4y agoStuff in ~/.ssh/config which complements the git config in OP: Host foo.bitbucket.org HostName bitbucket.org User git IdentityFile ~/.ssh/foo_id As in, for using bitbucket.org with the private key ~/.ssh/foo_id, you'd instead clone from foo.bitbucket.org:owner/repo.
- dietr1ch 4y agoWhy not just create a new user? I feel that this warrants some isolation. This allows having everything just under ~/Projects and having special configs without too much hassle IMO, it seems cleaner than using branching configs. You can still symlink the shared bits. To work you just `su $WORK/SCHOOL_USER` to get a simple shell, use ssh+tmux to get a session, and can use editors/browsers/etc configured specifically for that user (purpose). In case you want more uniformity when editing you can use tramp (or something similar).
- AndyJames 4y agoDifferent addresses for different repos are pretty straightforward. Can someone tell me please how to use multiple SSH keys. I have constant problem with Bitbucket because they require SSH key to be unique across whole platform. I work on many projects. Some companies require me to use Bitbucket account created by them with their email address. I can't add my SSH key to such account because it's already assigned to my private account. My workaround is to use GitKraken which allows assigning SSH keys per repo but I would really like to have this option in command line and don't need full GitKraken license just for pushing changes
- terinjokes 4y agoYou can use something like direnv to export GIT_SSH to point at a wrapper that invokes `ssh -i ~/.ssh/id_corp $@`.
- olddustytrail 4y agoThere's an option in newer git. For cloning new repo: git clone -c "core.sshCommand=ssh -i ~/.ssh/bitbucket-work -F /dev/null" git@bitbucket.com:example/example For existing repo: git config core.sshCommand "ssh -i ~/.ssh/bitbucket-work -F /dev/null" Where "bitbucket-work" is the name of the key for that particular repo.
- Macha 4y agoI tend to just configure my .ssh/config file to create an entry for github-companya with host github.com and identity file ~/.ssh/companya (or replace GitHub with bitbucket in your case)
- mleo 4y agoOn BitBucket, at least, you can utilize wildcard DNS and use different hostnames with SSH keys. $ git clone git@workspace.bitbucket.org:workspace/repo.git I haven't tried with GitHub as I only have one account I use there.
- rad_gruchalski 4y agoI do it like this: https://gruchalski.com/posts/2022-04-28-private-go-modules-with-multiple-git-identities/ https://gruchalski.com/posts/2022-04-28-private-go-modules-w.... This is in the context of go modules but it works with regular git stuff.
- __warlord__ 4y agoI use this: https://memooo.ooo/posts/git-multiple-identities/ https://memooo.ooo/posts/git-multiple-identities/
- clircle 4y agoThere’s also an easy emacs package for that. https://github.com/akirak/git-identity.el https://github.com/akirak/git-identity.el
- funcDropShadow 4y agoYes, but the solution of the original post does not need additional tools. I.e. it works in- and outside of emacs.
- lsaferite 4y agoMy answer to this is `direnv` and silo-specific subdirs where I set the git email ENV variables so that all projects default to the right email. Work quite well. I also keep my AWS_PROFILE setting and a few more things in those silo-specific `.envrc` files.
- infensus 4y ago...or just set email per repository and leave it empty in the global config?
- seltzered_ 4y agoThere's karn: https://github.com/prydonius/karn https://github.com/prydonius/karn which does a decent job of managing git identities based on folder location, configurable via yarn file