iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📘

Using a work GitHub account only for company repositories

に公開

TL;DR

I want to separate my GitHub accounts for personal and work use, but
switching id_rsa files is a hassle.

Conclusion: Use GitHub CLI

In Git's credential configuration, you can set authentication methods for specific domains.

While various authentication methods are available, GitHub CLI is the easiest to set up.

Steps

  1. Install gh
brew install gh
  1. Log in to GitHub with your work account in your default browser.
  2. Run the following command in your terminal to authenticate:
gh auth login
  1. Add the following to $HOME/.gitconfig:
    • If the username for your company's repository is kaisha and your personal work account username is tanaka, use kaisha.
[credential "https://github.com/company_repo_username"]
	helper = !gh auth git-credential
  1. Clone your company's private repository using https. Confirm that user authentication is not required.

It's a good idea to use two different browsers, like Chrome and Firefox, to log in with your personal and work accounts separately.

Bonus

Though I haven't investigated it thoroughly, gitprof also seems easy.

Discussion