# Setting Up Multiple Git Accounts on MacManaging multiple Git accounts on the same machine can be simplified with the following steps. This guide ensures you can seamlessly work with personal and work accounts.---## 1. Create SSH Keys for Each AccountGenerate separate SSH key pairs for each GitHub account:\`\`\`bashcd ~/.sshssh-keygen -t rsa -C "[email protected]" -f "github-personal"ssh-keygen -t rsa -C "[email protected]" -f "github-work"\`\`\`- Replace the email addresses with the ones associated with your respective GitHub accounts.- The `-f` flag specifies the filenames for the key pairs.---## 2. Add SSH Keys to the SSH AgentAdd the generated keys to your SSH agent:\`\`\`bashssh-add --apple-use-keychain ~/.ssh/github-personalssh-add --apple-use-keychain ~/.ssh/github-work\`\`\`For Linux or non-Mac environments:\`\`\`bashssh-add ~/.ssh/github-personalssh-add ~/.ssh/github-work\`\`\`---## 3. Add Public Keys to GitHubCopy each public key and add them to the corresponding GitHub accounts.\`\`\`bashpbcopy < ~/.ssh/github-personal.pub # Maccat ~/.ssh/github-personal.pub | xclip -selection clipboard # Linux\`\`\`1. Go to [GitHub SSH Settings](https://github.com/settings/keys) for each account.2. Click **"New SSH Key"**, paste the public key, and save.Repeat for the second account:\`\`\`bashpbcopy < ~/.ssh/github-work.pub\`\`\`---## 4. Configure SSH for Multiple AccountsEdit the SSH config file to define separate host entries for each account:\`\`\`bashopen -e ~/.ssh/config # Macnano ~/.ssh/config # Linux\`\`\`Add the following configuration:\`\`\`text# Personal accountHost github-personal HostName github.com User git IdentityFile ~/.ssh/github-personal# Work accountHost github-work HostName github.com User git IdentityFile ~/.ssh/github-work\`\`\`---## 5. Set Default Git ConfigurationsSet your global Git username and email for the default (personal) account:\`\`\`bashgit config --global user.name "Your Personal Name"git config --global user.email "[email protected]"\`\`\`For repositories requiring your work account, override the default configuration:\`\`\`bashcd /path/to/your/repositorygit config user.name "Your Work Name"git config user.email "[email protected]"\`\`\`---## 6. Clone Repositories with Correct AccountsUse the host alias defined in the SSH config:- For personal account: \`\`\`bash git clone git@github-personal:username/repo.git \`\`\`- For work account: \`\`\`bash git clone git@github-work:username/repo.git \`\`\`---## 7. Update Existing Repository RemotesTo switch the account used by an existing repository:\`\`\`bashgit remote set-url origin git@github-work:username/repo.git\`\`\`---## 8. Test SSH ConnectionVerify the SSH setup for each account:\`\`\`bashssh -T github-personalssh -T github-work\`\`\`You should see a welcome message for each respective GitHub account.---## 9. Optional: Switch Accounts EasilyCheck which account is in use for a repository:\`\`\`bashgit config user.namegit config user.email\`\`\`Update them as necessary:\`\`\`bashgit config user.name "Your Work Name"git config user.email "[email protected]"\`\`\`