β git: configure identities for work
β’ 225 words β’ 2 min β’ updated
Problem statement: Given two sets of git configurations, one for personal projects and one for work, how can you effectively separate them?
Workflow #
I like the following workflow.
First, create your usual ~/.gitconfig. It will be used for your personal
project:
[user]
name = Thiago Perrotta
email = {personal-email}
[...]
# Import corp configs if any.
[include]
path = .gitconfig_corpThis config should live in your personal laptop and in your work laptop.
Normally I include it via my .dotfiles
(git repo) i.e. with a simple stow git away.
And we are done with our personal laptop.
Now, for the work laptop, create ~/.gitconfig_corp:
[includeIf "gitdir:~/Orgname/**"]
path = .gitconfig_orgname
[includeIf "hasconfig:remote.*.url:git@github.com:orgname/**"]
path = .gitconfig_orgname
# vim: ft=gitconfigThe corp config is conditionally included / used in the following scenarios:
- whenever I am working on a git repository that lives within
~/Orgname - whenever the git remote of the repository I am working on is a git repository
under the organization
orgname
This config is usually included via my corp dotfiles (named .dotfiles_corp in
git), which is a separate git repository. There’s no fiddling with git
submodules: both git repositories are cloned and managed independently.
And now, last but not least, is the actual git config for work:
[user]
name = Thiago Perrotta
email = {work-email}
# vim: ft=gitconfigInspired by benji.dog.