Reputation: 1424
I use my personal laptop for work (they are fine with it) but I have noticed that all my work commits use my personal email address. I don't want to default to my work email address globally on my machine for git, is there a way that when I commit I can have my personal email address for some repos and my work email for others?
I'm not bothered about rewriting the history on the existing commits, just moving forward.
Upvotes: 3
Views: 1583
Reputation: 31117
Another solution than the one provided by @RomainValeri is to use the "Conditional include" git feature (that I find more convenient because you don't have to forgot to set the email in each new repository --it is automatically applied if you create the repository in the good work or personal folder--)
You could put all your personal repositories in a specific folder (here ~/personal/
) and set the config so that when you use git, it will use a specific configuration for all the repositories inside this folder.
That way, you won't forget to set the personal settings when cloning or creating a new repository.
You could do it like that:
In ~/.gitconfig
[user]
name = John Doe
email = [email protected]
[includeIf "gitdir:~/personal/"]
path = ~/personal/.gitconfig
In the new config file containing your personal information ~/personal/.gitconfig
:
[user]
email = [email protected]
edit: reading again your question and because that's your personal computer, perhaps you would like to do the opposite, so you just have to switch both emails...
Upvotes: 6
Reputation: 21918
Yes, you can take advantage of --local
settings to precisely manage what email each repo should use.
# to set your work email only for the current repo
git config --local user.email '<your work email>'
# to set an email globally, as a fallthrough if a repo doesn't have a local setting for user.email
git config --global user.email '<your personal email>'
Upvotes: 4