The dotfiles I use to configure my Linux system are now publicly available in a Git repository.
For years I’ve tracked my configuration files, sharing them across systems in a private GitHub repository. But I’ve learned a lot of tricks reading the dotfiles of others (especially while setting up nvim) so I’ve decided to pay that forward by sharing mine. Interestingly, when making a new repo I looked around for how others are doing it and found a much better way than my old approach of making symlinks from the home folder to the local repository.
--work-tree, and a Git alias
I came across How to manage your dotfiles in Git by Paul Gasking. It lays out an interesting set of Git options, most notably creating an alias used to call your dotfile repository git actions from anywhere on the system. The approach is novel, allowing any file in your Home directory to be individually added to the repo.
I didn’t fully understand why this works so I found Gabrielle Young’s article
The best way to store your dotfiles: A bare Git repository
that clears everything up. By default, a repository always has a
.git folder at
root, but that’s not a hard and fast requirement.
- Use the
--git-dirdirective to specify a different
- Set the root of the repo somewhere else using
Silencing untracked files and automating the custom
With my Home directory as the work tree, and a subdirectory for the
folder, Git will normally see every file in Home as untracked. Setting
no in the Git config is necessary to silence
the madness. Now, only files explicitly added to the repo will be tracked for
Finally, a clever use of
alias lets me call Git with all of the necessary
alias config='/usr/bin/git --git-dir=$HOME/.cfg/.git/ --work-tree=$HOME'
When I make a change to a dotfile, I use the
config command as if I were
$ config add ~/.profile $ config status $ config diff --cached $ config commit -s $ config push
Pretty slick, right?
This is not a tutorial, so head over to Gabrielle’s guide if you want to get set up the same way. For now I have my Bash and Neovim dotfiles posted, but will be adding more as I clean up my system config.