1

I'm attempting to create a personal .gitconfig file to serve my personal and professional needs when coding.

I have managed to get credentials to be saved differently based on where the repo is located. See the Git config snippet below:

[credential "https://github.com"]
        username = "myUsername"
        helper = "store"

This seems to work fine and I am happy with the results.

I am now trying to do the same to user.name and user.email aswell. See the Git config snippet below:

[user "https://github.com"]
        email = "<private email>"
        name = "<private alias>"

When I use this config and attempt to commit something, Git refuses and says:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"   git config
--global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

I am certain that the repository I am committing against is located on GitHub.

I have seen some people use different include statements to solve this, but I would prefer to solve it with subconfigs if possible.

Can someone please help me get this working or at least explain why it is not possible (if that would be the case).

Thanks for any help.

Hannes Knutsson
  • 111
  • 1
  • 14
  • 1
    user.mail and user.email affect _revisions_ themselves, so..... are you talking about creating duplicate revisions? – eftshift0 Aug 03 '20 at 18:47
  • All I wish is that when I commit towards a repo located on GitHub I will use email1 and name1, and when I commit towards a repo on a private server I will use email2 and name2. Does that make sense? :) @eftshift0 – Hannes Knutsson Aug 03 '20 at 18:50
  • 3
    When you _commit_ you do not work with a remote repo.... you commit on a local repo... and the email and email will be what you have in settings..... then when you push to X numbers of repos, the revisions will be pushed as they were committed, no relation to whatever remote you want to push to. – eftshift0 Aug 03 '20 at 18:54
  • That's right.. Hmm.. so that explains why the credential setting works, but not name/email, aswell. Do you see any way to conveniently accomplish what I am trying to do here, or am I doomed to juggle different configs and import statements until I reach my goal? If you respond with your last comment as an answer I will mark it as correct :) Thanks for your help, @eftshift0 . – Hannes Knutsson Aug 03 '20 at 19:03
  • 1
    I obviously meant "name and email" – eftshift0 Aug 03 '20 at 19:03

1 Answers1

0

This is generally done with, indeed, include/includeif section within your global config file (I never seen subconfig for user.name).

[includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig

Any repository inside ~/work would then use ~/work/.gitconfig in which you can define a different set of user.name/user.email settings.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250