DEV Community

Ishaan Mittal
Ishaan Mittal

Posted on

How to Use Two GitHub Profiles on One Machine

Hey there! I'm going to show you how to use two GitHub profiles on one machine. This is useful if you have a personal and a work GitHub account and want to keep them separate. I faced this issue when I needed to have a separate GitHub account for all my 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 machine.

Pre-requisites

  • A GitHub account (two accounts if you want to follow along)
  • Git installed on your machine

Installing GitHub CLI

GitHub CLI is a command-line tool that allows you to interact with GitHub from the terminal. You can install GitHub CLI by following the instructions on the GitHub CLI website.

Authenticating your GitHub Accounts

Once you have GitHub CLI installed, you can authenticate your GitHub accounts by running the following commands in your terminal:

gh auth login
Enter fullscreen mode Exit fullscreen mode

This command will prompt you to log in to your GitHub account using your web browser. Keep the browser having the desired account open to which you want to authenticate before running the command.

After Logging in, confirm that you have logged in to both accounts by running the following command:

gh auth status
Enter fullscreen mode Exit fullscreen mode

You should be able to see your two authenticated accounts and the account that is currently active with Active Account set to true under that account.

You can switch between active accounts by running the following command:

gh auth switch
Enter fullscreen mode Exit fullscreen mode

The active account gives you access to the repositories associated with that account.

Using Two GitHub Profiles

  1. To have access to your desired account and its GitHub repositories, make that account your active account using GitHub CLI:
gh auth switch
Enter fullscreen mode Exit fullscreen mode
  1. To associate your commits with your desired GitHub account, set the user name and email for your account for that repository.:
git config user.name "Your Name"
git config user.email "personalEmail@gmail.com"
Enter fullscreen mode Exit fullscreen mode

If you want to use any one of your accounts for most of your repositories, you can use the global option --global to set the user name and email for all repositories on your machine.

Refer to the Git documentation for more on who your commits are associated with your GitHub account.

Let me know if you have any questions. I hope this helps you in managing your personal and work GitHub accounts on one machine. Happy coding!

Top comments (0)