Host github.com-work
Hostname github.com
User <YOUR GITHUB USERNAME>
IdentityFile ~/.ssh/<YOUR WORK SSH KEY>
So when you do git stuff in your work repositories, git will first rewrite the URLs to git@github.com-work and the underlying SSH will then use this host to look up the related configuration part and make calls to the real github.com again. The git@github.com-work address becomes just a label between git and ssh, but you as a user shouldn't need to do anything manually.
For Q2: The switching is done through convention, meaning: it depends on where the repository lives on your disk.
The convention is, personal projects shall go into the ~/Development/Personal/ folder, and work related repos in ~/Development/Work/.
includeIf is as the name suggest a conditional loading, the condition is "where on the computer is the action happening".
Note: to also support repos outside of those two locations, the personal profile is the default for everything. You can decide on your work machine to use instead the work profile instead; for that adjust the config location of the following piece:
# this is the default for any location on your computer
[include]
path = ~/.gitconfig.personal # change that if needed
To Q3: As already touched by the answer to Q2, the switching happens solely based on the location on your computer. That is literally the only "magic" in this whole approach. Place the repos into the right locations and the matching configuration will be used.
Hi there,
For Q1: No, you don't have to do that at all, that's why we have the following piece in the git config:
and the matching ssh config:
So when you do git stuff in your work repositories, git will first rewrite the URLs to
git@github.com-work
and the underlying SSH will then use this host to look up the related configuration part and make calls to the realgithub.com
again. Thegit@github.com-work
address becomes just a label between git and ssh, but you as a user shouldn't need to do anything manually.For Q2: The switching is done through convention, meaning: it depends on where the repository lives on your disk.
The convention is, personal projects shall go into the
~/Development/Personal/
folder, and work related repos in~/Development/Work/
.includeIf
is as the name suggest a conditional loading, the condition is "where on the computer is the action happening".Note: to also support repos outside of those two locations, the personal profile is the default for everything. You can decide on your work machine to use instead the work profile instead; for that adjust the config location of the following piece:
To Q3: As already touched by the answer to Q2, the switching happens solely based on the location on your computer. That is literally the only "magic" in this whole approach. Place the repos into the right locations and the matching configuration will be used.
Does that clarify it for you?
Yes, I can't thank you enough.