DEV Community

Cover image for How to set Git for multiple GitHub accounts
mtilson
mtilson

Posted on

How to set Git for multiple GitHub accounts

Alt Text

Let's say we have GitHub org with team of 2 members (member1, member2) having Write access to a repo with URL of https://github.com/org/repo.git

We are going to setup Git (repository and global options) on macOS to be able to commit to the repo using the above GitHub user accounts including different network authentication

  • Configure macOS system credential helper
git config --system credential.helper osxkeychain
git config --system credential.usehttppath true
  • Remove user personal name and email from system configuration
git config --system --unset user.name
git config --system --unset user.email
  • Setup member1 account
login member1
  • Get repo
mkdir -p ~/projects
cd ~/projects
git clone https://github.com/org/repo.git
cd repo
  • Setup user personal name and email
git config user.name member1
git config user.email member1@email.io
  • Setup authentication credentials
git config credential.username member1
  • Repeat the above steps for member2 account
login member2
  • Get repo
mkdir -p ~/projects
cd ~/projects
git clone https://github.com/org/repo.git
cd repo
  • Setup user personal name and email
git config user.name member2
git config user.email member2@email.io
  • Setup authentication credentials
git config credential.username member2

Now user names, emails, and credential names are stored in the corresponding repo's .git/config and will be used by Git to push commits to GitHub on behalf of the corresponding users

Alt Text

Top comments (0)