Like a good Linux user, I keep my dotfiles on git repositories.
When I set up a new machine, I do
|
|
which includes my dotfiles for most things, which are common across all my machines, whether for work or personal use.
However, some things cannot be kept on public repos, and cannot be the same across all machines, such as git configs.
Git config structure
Previously I used to keep a single git config file in the linux_config repo, which contained my personal account info. Whenever I set up a new machine for work, I had to manually change the git config to use my work email and name.
Recently I learned there was a built-in way to manage multiple git profiles using the include and includeIf directives in git config.
So now my main git config looks like this:
config
|
|
Note that it’s including another file ~/.config/git/profile.ini. This file contains the actual profile info, and is on another private repo.
profile.ini
|
|
Apparently the gitconfig file syntax is not exactly .ini, but I chose to use .ini extension for decent enough syntax highlighting.
The profile.ini file contains my work profile by default, and includes another file home.ini for my personal profile, which is only applied when I’m in the ~/git/ directory.
home.ini
|
|
This way, git will automatically use the correct profile based on which directory I’m in.
Directory structure
The linux_config repo contains a Makefile which sets up the dotfiles and git config.
|
|
The gitconfig file is at home/.config/git/config, which is symlinked to ~/.config/git/config by stow.
On the private repo side, the Makefile looks like this:
|
|
Directory structure is as follows:
|
|
By symlinking home.ini from the home directory, the make work target automatically sets up gitconfig to reference the correct personal profile.