1

I have two workspace directories (W1 & W2) and I would like to default the git user email to email1 for all git repositories under W1 and email2 for all git repositories under W2.

Is it possible to configure such setting where we can default the git config values for all repo under a certain directory?

This should apply to any newly created git repositories inside W1 and W2 as well without additional per-repository configuration.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Keen Sage
  • 1,899
  • 5
  • 26
  • 44
  • Don't think so. What you can do is set global the email you use most often, then set local for each repo when needed – Son Nguyen Jun 21 '20 at 06:59
  • 4
    I believe you can use `includeIf` directives in the global .gitconfig file to include different sub-configuration files depending on criteria, such as the path to the repository. You would then have to set up different such files with different names and email addresses, and include the right one. I don't have any experience with doing it, however, so I don't know if it actually works for you and how you would set it up, but look here for details - https://git-scm.com/docs/git-config – Lasse V. Karlsen Jun 21 '20 at 08:15
  • For the time being, I just wrote a bash script that will set a local email for all the repos under W1 and keep a different one at global level. But I have to make sure I run this whenever I create – Keen Sage Jun 21 '20 at 08:22
  • https://stackoverflow.com/search?q=%5Bgit%5D+different+email – phd Jun 21 '20 at 09:31
  • I'm confident that a.) this is not a duplicate, as it asks a more specific question than the duped question and b.) `includeIf` is a solid lead for this and might solve this, but I've not used it myself so I can't write a reliable answer with this info. @LasseV.Karlsen maybe you want to put that info into an answer? Edit: I've taken the liberty to rephrase and expand the question, please revert this if I missed the original intent. – Joachim Sauer Jun 21 '20 at 10:43
  • @phd please re-read the question, this is not a duplicate. – Joachim Sauer Jun 21 '20 at 10:45
  • Be sure I've done it before pointing to the duplicate. [This](https://stackoverflow.com/a/43884702/7976758) and other answers there give different good solutions. Conditional include is perhaps the best one. – phd Jun 21 '20 at 11:31
  • I agree that the original duplicate isn't a great one (dupes should be based on the question being asked, not the solution), but this _is_ still a dupe. I've added another dupe that's more clearly asking the same thing. [This answer](https://stackoverflow.com/a/48088291/354577) is likely the most helpful. – ChrisGPT was on strike Jun 21 '20 at 11:40

0 Answers0