0

I have a personal and Work Github Accounts.

By default, git user.email is set to my personal email address. (git config user.email)

Is there a way if I clone repos from Work github account - it will use work email address automatically? Or what is right approach?

I'll-Be-Back
  • 10,530
  • 37
  • 110
  • 213
  • Possible duplicate of [Can I specify multiple users for myself in .gitconfig?](https://stackoverflow.com/questions/4220416/can-i-specify-multiple-users-for-myself-in-gitconfig) – phd Feb 16 '19 at 14:00
  • https://stackoverflow.com/search?q=%5Bgithub%5D+two+different+emails – phd Feb 16 '19 at 14:00

2 Answers2

1

There are several levels of ranges for git config,

  1. --global, writes to ~/.gitconfig
  2. --system, writes to ${prefix}/etc/gitconfig
  3. --local, default, writes to project .git/config
  4. --worktree, writes to project .git/config.wroktree, similar to --local

You can use the project wide --local config files to override the --global value, that is, when you setup a project with work account, immediately git config to add a project wide user.name and user.email.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
  • Is there a better approach by using multiple accounts with `~/.gitconfig`? And maybe with the help of `git alias`? – Geno Chen Feb 16 '19 at 13:55
0

I suggest you configure your git with git config user.name & git config user.emailwhenever you need it. Otherwise, if you can work with your two accounts on the same project, you can add your second account as a contributor.

Madi Naf
  • 655
  • 1
  • 6
  • 19