Same. Nice thing about leaving the global config unset: as soon as you try to commit or amend Git prompts you for your name and email, at which point I fill in the repo config.
I also have 2 nice aliases that set the repo config’s name/e-mail fields: hg work and hg personal.
This is a really neat approach, I had no idea it worked! So far I’ve used direnv with a config that exports “GIT_AUTHOR_EMAIL”. It’s neat that the git config supports this out of the box.
I use the same directory structure to separate my repositories and wrote a little wrapper for git-clone to automate it: https://gitlab.com/3point2/git-cu.
The includeIf is new to me and very useful, thanks!
I’ve done this for a while and it really helps. If you ever find you goofed the wrong email, you can amend any commits with git commit --amend --author="username <user@email.addr>" --no-edit
; include only if a remote with the given URL exists (note
; that such a URL may be provided later in a file or in a
; file read after this file is read, as seen in this example)
[includeIf "hasconfig:remote.*.url:https://example.com/**"]
path = foo.inc
[remote "origin"]
url = https://example.com/git
I use this to manage work vs. nonwork email addresses by repo remote. This is how I do it (edited to show a git@ remote URL rather than just https). In my ~/.gitconfig:
I’ve left my git global config unset. When I make a new repo and put it under git I do
git config user.name
anduser.email
I don’t create so many repos per day that I can’t spend a few minutes setting this up at the same time I set up remotes.
Same. Nice thing about leaving the global config unset: as soon as you try to commit or amend Git prompts you for your name and email, at which point I fill in the repo config.
I also have 2 nice aliases that set the repo config’s name/e-mail fields:
hg work
andhg personal
.This is a really neat approach, I had no idea it worked! So far I’ve used direnv with a config that exports “GIT_AUTHOR_EMAIL”. It’s neat that the git config supports this out of the box.
I use the same directory structure to separate my repositories and wrote a little wrapper for git-clone to automate it: https://gitlab.com/3point2/git-cu.
The includeIf is new to me and very useful, thanks!
I’ve done this for a while and it really helps. If you ever find you goofed the wrong email, you can amend any commits with
git commit --amend --author="username <user@email.addr>" --no-edit
Can you do the same include matching based on repo URL? I may have to try that out.
With git 2.37 you can use a remote - this example is taken directly from https://git-scm.com/docs/git-config:
I use this to manage work vs. nonwork email addresses by repo remote. This is how I do it (edited to show a git@ remote URL rather than just https). In my ~/.gitconfig:
Then, for example, ~/dotfiles/shared/gitconfigs/gitlab:
Thank you so much for sharing! This is going to save me a lot of time.
Right on, I’m glad to hear that!
oh this would’ve saved me so much hassle
I personally use https://github.com/DrVanScott/git-clone-init to automatically setup a different user.name/user.email according to the cloned domain.