You can have different keys based on different domains. The following code is an example of how you can configure your SSH keys for different accounts on GitHub and Bitbucket.
code ~/.ssh/config
# Personal account
Host github.com
HostName github.com
User git
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
# Work account-1
Host bitbucket.org
HostName bitbucket.org
User git
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
Multiple git configs
If you want to have multiple git configs one of the easiest ways to achieve this is having a separate workspaces and gitconfigs respectively.
In the context git, a workspace refers to a directory or folder on your computer where you store your work-related projects and files.
By using the includeIf directive in your .gitconfig file, you can tell Git to use a specific configuration file depending on which workspace you're currently in.
In case you don't have a gitconfig;
touch .gitconfig
code .gitconfig
Inside of .gitconfig separate config files based on path
[includeIf "gitdir:/Users/your_username/workspace-company/"]
path = ~/.gitconfig-company
[includeIf "gitdir:/Users/your_username/workspace-personal/"]
path = ~/.gitconfig-personal
then in each config you’ll have different setup.
.gitconfig-company
[user]
name = Orhun Ozer
email = orhun.ozer@company.com
.gitconfig-personal
[user]
name = HelluvaDevelopa
email = helluva@developa.com
Resources freecodecamp
Top comments (0)