Managing Multiple GitHub Accounts on the Same Computer
3 min read
Problem Statement ๐
You have two GitHub accounts: user1 (private) and user2 (work-related), and you want to use both accounts on the same computer without typing passwords every time you use Git.
Solution Overview โ
Use SSH keys with host aliases in an SSH config file and configure different .gitconfig user credentials based on your current working directory.
This will allow you to change github credentials based on what working directory youโre in.
Step-by-Step Implementation ๐
1. Navigate to Your Home Directory
Ensure youโre in your home directory (~). You should already have a .ssh folder by default. Since itโs a hidden folder, use ls -a to see it. If it doesnโt exist, create it with:
mkdir ~/.ssh
2. Generate SSH Keys for Both Accounts
Navigate to your .ssh directory and run these commands:
You can verify your current Git configuration by running:
git config --list
This command displays both global and local Git configurations. Local configurations can be found in .git/config within each repository.
Summary ๐
You now have a complete setup for managing multiple GitHub accounts on the same computer. Each account will use its respective SSH key and user configuration based on your working directory.