Chapter 28: Managing Multiple Git Accounts with SSH Config
In this chapter, you'll learn how to manage multiple Git accounts on the same system using SSH aliases and how to configure per-repository identities with Git’s includeIf directive.
In the previous chapter, you learned how to use Git over SSH with GitHub, GitLab, and Bitbucket. You also configured the ~/.ssh/config file so SSH automatically uses the correct key for each platform. That setup works well when you only have one account per service.
But many developers later run into a common problem. You might have one GitHub account for personal projects and another GitHub account for work. Both accounts use github.com, so SSH cannot automatically tell which account you want to use.
Because of this, Git may use the wrong SSH key when you run commands like git push,which can lead to permission errors or commits being pushed with the wrong account.
In this chapter, you'll learn how to properly set up multiple GitHub accounts on the same system, so Git always uses the correct SSH key for each repository.