{"thread":{"id":"64747","subject":"git init with specified user.email","startedAt":"2026-01-08T17:21:34Z","lastAt":"2026-01-08T23:22:14Z","messageCount":2,"participants":["David Miguel Susano Pinto","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"533290","messageId":"875x9cvx44.fsf@word","threadId":"64747","inReplyTo":null,"subject":"git init with specified user.email","fromName":"David Miguel Susano Pinto","fromEmail":"carandraug@gmail.com","sentAt":"2026-01-08T17:21:31Z","receivedAt":"2026-01-08T17:21:34Z","isPatch":false,"sender":{"key":"carandraug@gmail.com","avatar":null},"body":"git checkout has a --config option so one can do:\n\n    git clone --config 'user.email=email-for-this-clone' ...\n\nwhich I find nice to setup as git alias:\n\n    clone-work = clone --config 'user.email=my-work-email'\n\n(while leaving the default clone for my personal projects; or an alias\nfor clone-personal with the work email as the clone default).\n\nI would like something similar for git init.  However, git init does not\nhave a `--config` option.  I tried to use\n\n    git -c 'user.email=my-work-email' init\n\nbut that's not working (I'm guessing it only picks up configurations\nmentioned on the man page for git-init).\n\nI am currently working around this with a template for work but would\nprefer to init with `-c` (or similar) or at least understand why this is\nnot possible.\n\n--\nDavid\n"},{"id":"533306","messageId":"aWA8I82PXXVjiMVR@fruit.crustytoothpaste.net","threadId":"64747","inReplyTo":"875x9cvx44.fsf@word","subject":"Re: git init with specified user.email","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2026-01-08T23:22:11Z","receivedAt":"2026-01-08T23:22:14Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2026-01-08 at 17:21:31, David Miguel Susano Pinto wrote:\n> git checkout has a --config option so one can do:\n> \n>     git clone --config 'user.email=email-for-this-clone' ...\n> \n> which I find nice to setup as git alias:\n> \n>     clone-work = clone --config 'user.email=my-work-email'\n> \n> (while leaving the default clone for my personal projects; or an alias\n> for clone-personal with the work email as the clone default).\n\nThe reason this functionality exists is because it sets those\nconfiguration variables as soon as the repository is initialized and\n_before_ actually downloading the data.  As an example, if you wanted to\nset a split index or a default line ending configuration, you'd want to\nset that before the index was created and the working tree was checked\nout, so you can't do that after the clone command completes.\n\n> I would like something similar for git init.  However, git init does not\n> have a `--config` option.  I tried to use\n> \n>     git -c 'user.email=my-work-email' init\n> \n> but that's not working (I'm guessing it only picks up configurations\n> mentioned on the man page for git-init).\n\n`git -c` (where `-c` precedes the subcommand) is different.  It sets the\nconfiguration option _for this command only_ and doesn't save it in the\nconfig.  For instance, if you want to run a single diff command without\ncolours, you can run `git -c color.diff=false diff`; that won't affect\nany of the configuration files.\n\nThe reason that Git doesn't provide a config option for `git init` is\nbecause, except for things like the hash algorithm and ref format,\nalmost nothing is done to the repository when the command completes.\nThere isn't even an index created, so setting configuration like split\nindex in a separate configuration command isn't a problem.\n\n> I am currently working around this with a template for work but would\n> prefer to init with `-c` (or similar) or at least understand why this is\n> not possible.\n\nThis is possible with an alias like so:\n\n    init-work = \"!f() { dir=\\\"$1\\\"; shift; git init \\\"$@\\\" \\\"$dir\\\"; git -C \\\"$dir\\\" config set user.email my-work-email; }\"\n\nThis would work slightly differently in that you'd need to specify the\ndirectory first unless you wanted to adjust the alias to do more\ncomplicated shell parsing.  You could also implement a shell script\ncalled `git-init-work` (using `git rev-parse --parseopt`[0] or otherwise)\nthat would handle the complexities and it would work just like the\nalias as long as you put it in `PATH`.\n\nOne other approach that might work for you is the includeIf\nfunctionality in the config file.  You could do something like this in\nyour main config file:\n\n    [includeIf \"gitdir:~/checkouts/work/**\"]\n        path = ~/.config/git/config-work\n\nAnd then set the `user.email` value in `~/.config/git/work`.  That would\nmean that any repositories under `~/checkouts/work` would automatically\nhave the config values in `~/.config/git/config-work` set.\n\n[0] If you want an example of using `git rev-parse --parseopt`, you can\nsee https://github.com/bk2204/dotfiles/blob/dev/bin/dct-mtree, which\ndemonstrates some of the functionality.  The manual page is also\nhelpful.\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"}]}