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 --workTo set the git configuration for personal use:
./set_git_config.sh --personalTo 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 "your_personal_email@domain.com" -f ~/.ssh/id_rsa_personal
# For work use
ssh-keygen -t rsa -b 4096 -C "your_work_email@domain.com" -f ~/.ssh/id_rsa_workCreate 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.gitNote the change from the typical git@github.com/ 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