Hey! I’ll show you how to use two GitHub profiles on one computer. This is useful if you have a personal GitHub account and a work GitHub account and want to keep them separate. I ran into this problem when I needed to have a separate GitHub account for all company-related work. I wanted to keep my personal projects separate from my work projects, so I had to figure out how to use two GitHub profiles on one computer.
Prerequisites
- A GitHub account (you’ll need two if you want to proceed)
- Git installed on your machine
Install GitHub CLI
GitHub CLI is a command-line tool that allows you to interact with GitHub from your terminal. You can install the GitHub CLI by following these instructions GitHub CLI website.
Verify your GitHub account
After installing the GitHub CLI, you can authenticate your GitHub account by executing the following command in your terminal:
gh auth login
This command will prompt you to log in to your GitHub account using a web browser. Before executing the command, keep the browser open for the desired account you want to verify.
Once logged in, confirm that you are logged into both accounts by executing the following command:
gh auth status
You should be able to see your two authenticated accounts as well as the currently active account Active Account
set to true
under this account.
You can switch between active accounts by executing the following command:
gh auth switch
Active accounts give you access to the repositories associated with the account.
Use two GitHub configuration files
- To access the account you want and its GitHub repository, use the GitHub CLI to make that account your active account:
gh auth switch
- To associate your commits with the required GitHub account, set a username and email for the repository’s account.
git config user.name "Your Name"
git config user.email "personalEmail@gmail.com"
If you want to use any one account for most of your repositories, you can use the domain-wide option --global
Set up a username and email for all repositories on your computer.
See Git documentation Learn more about how your commits are associated with your GitHub account.
If you have any questions please let me know. I hope this helps you manage your personal and work GitHub accounts on one computer. Happy coding!