Splitting .gitconfig based on project
I keep my personal projects separate from my work-related projects in git. This requires remembering what I'm currently working on and applying that profile to the commits, git_template, etc.
This allowed me to get rid of bash functions that setup my git configuration (e.g. GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL) depending on what I was working on.
So I ended up with the following ~/.gitconfig:
[user]
name = Amit Kucheria
[includeIf "gitdir:~/work/sources/"]
path = ~/.gitconfig-linaro
[includeIf "gitdir:~/work/sources/personal/"]
path = ~/.gitconfig-personal
My ~/.gitconfig-linaro looks like this:
[user]
email = "amit.kucheria@work.com"
My ~/.gitconfig-personal looks like this:
[user]
email = "amit.kucheria@personal.com"
One thing to remember, the order of the includeIf statements matter! They should be ordered from generic to more-specific directories if like me, all your sources live in a single folder. If the order in the above snippet were reversed, you'd always end up using the .gitconfig-linaro configuration.
One less thing to remember to set as I switch between work and personal projects.
Comments