There are some nuances. Took me a bit to piece it all together.
- Just add an if condition at the end of your existing global
.gitconfig
at your root directory.
[includeIf "gitdir:~/something/personal/"]
path = .gitconfig-personal
[includeIf "gitdir:~/elsewhere/work/"]
path = .gitconfig-work
The reason for adding at the end of your config, is because you want to inherit everything that's in your existing config, but then just override with some other directory based configurations.
ATTENTION: You must also add the /
at the end of your directories. Otherwise things won't work.
- Create and add whatever overrides you want into
.gitconfig-personal
,.gitconfig-work
. For example mine is just:
# .gitconfig-personal
[user]
name = mfaani
email = [email protected]
# .gitconfig-work
[user]
name = Mohammad Faani
email = [email protected]
Either:
- Inspect existing repos:
git config --list | grep user.name
in different directories and inspect if things are different. - Inspect new repos:
- cd personal
- git init Foo
- cd Foo
- git config user.name
- compare its value if you did the same steps but from within /work directory