Hacker News new | ask | show | jobs
by 3np 1765 days 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
1 comments

Thank you. The `host` field always has to have the format `word.word`? Or it can be just `word` without any dot in the middle?
You can call it anything you want save of whitespace (albeit I personally haven't tried emoji or other non-ASCII shenanigans :))
Thank you. Why is it that all examples in this thread use `.com` somewhere in the middle of the string used for the `host` field?
I 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.

Personally I just found it natural to tack on a suffix. But you do you :)
Why is it natural? Do hosts usually have a suffix? Why?