3 ms·
So one thing you can do is put the following in your ~/.gitconfig: [includeIf "gitdir:/home/john/corp/**"] path = .gitconfig-corp And then ~/.gitconfi
by 3np 5y ago
So one thing you can do is put the following in your ~/.gitconfig:
[includeIf "gitdir:/home/john/corp/**"]
path = .gitconfig-corp
And then ~/.gitconfig-corp:
[user]
email = john@example.com
name = John Doe
[url "git@github.com-corp"]
insteadOf = git@github.com
Now all repos under the path /home/john/corp/ will use that config. Then you can put a new host in your SSH config:
Host github.com-corp
HostName github.com
User git
IdentityFile /home/john/.ssh/corp_github
This way you can have different e-mail address and name in your commit messages as well.
Due to the nature of git you can't scope it via GH URL (you can have many remotes in the same local repo). Though you can still manually rewrite when you add a remote with just the SSH config change, e.g.
git clone git@github.com-corp:corp/foobar.git
- renerthr 5y agoThank you. The `host` field always has to have the format `word.word`? Or it can be just `word` without any dot in the middle?
- 3np 5y agoYou can call it anything you want save of whitespace (albeit I personally haven't tried emoji or other non-ASCII shenanigans :))
- renerthr 5y agoThank you. Why is it that all examples in this thread use `.com` somewhere in the middle of the string used for the `host` field?
- 3np 5y agoPersonally I just found it natural to tack on a suffix. But you do you :)
- renerthr 5y agoWhy is it natural? Do hosts usually have a suffix? Why?
- 3np 5y agoI guess if you have a more complex matrix of personas and remote servers (not only GH), structure and predictability becomes more important than terseness. But again, it's just personal preference.