Setting Git username and email without using .gitconfig?
All settings can be set on a per repository basis : just drop the --global
from your git config
commands :
# from inside your repo :
git config user.name "Your Name"
git config user.email [email protected]
These config settings will then be stored in the .git/config
file (in the repo folder), and will take precedence over global config options.
This works for any git config option (aliases, colors, ...)
note : you will have to repeat the config for any new clone you make, or for any other repo where you want to use this identity
I figured out the solution:
Add the following to your dotfiles' .gitconfig
file:
[user] # These values are set in ~/.gitconfig_local
[include] path = ~/.gitconfig_local
Create a file in ~/
called .gitconfig_local
and add the values you don't want committed or made public in your .gitconfig
file. In this case:
[user] name = First Last email = [email protected]
As you might guess, the [include]
command "links" to the local, secondary configuration file which is outside the repository and thus private. The remainder of your settings in .gitconfig
such as your aliases, colour and editor settings etc. will still be public.