This repository contains a script to switch between personal and work git configurations and instructions on setting up SSH for multiple identities.
This script allows you to set local git credentials for either work or personal use.
To set the git configuration for work, in your local directory corresponding to the git repo you wish to work on type:
./set_git_config.sh --work
To set the git configuration for personal use:
./set_git_config.sh --personal
To manage multiple SSH identities (e.g., for GitHub or Gitlab), you need to set up your ~/.ssh/config
file.
Generate separate SSH keys for personal and work use if you haven't already:
# For personal use
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_personal
# For work use
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_work
Create or edit your ~/.ssh/config
file with the following content:
If you have pre-generated ssh keys you can simply point the IndetityFile
attribute to those files instead of the default.
# Personal GitHub account
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes
# Work GitHub account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
IdentitiesOnly yes
Update the remote URL for your Git repositories to use the appropriate SSH alias.
For a personal repository:
git remote set-url origin git@github-personal:username/repository.git
Note the change from the typical [email protected]/
to git@github-personal
(You can set up whatever name you want but make sure it corresponds with the Host attribute in your .ssh/config file)
Similarly, For a work repository:
git remote set-url origin git@github-work:username/repository.git