Managing dotfiles in `git`
(2024-07-08)
[note]
Dealing with dotfiles can be a nuisance. I use a method that I read about in this Git tutorial (which is in turn based on a Hacker News post).
It is the most elegant approach I've come across. It does not need to clutter your home directory, it does not cause your shell prompt to show Git status info whenever you're in a subdirectory of $HOME. It stays out of the way, but is still instantly accessible whenever you need it and allows you to use the full power of Git.
Check out the linked tutorial for the full rundown. Here's the core idea, with my personal improvements added on top.
- Use
git init --bareto initialize a baredotfilesGit repository somewhere on your file system. I used$HOME/.dotfiles/. This repository will track all of your dotfiles while hiding away in a convenient location, which is not your home directory root. - Add a shell alias that uses this newly created bare dotfiles repository:
- Configure the
dotfilesrepo to not show untracked files in status output:
- Add some prints to your shell
rcfile in order to be reminded when you have forgotten to sync your stuff:
dotfiles_status=""
if ! | ; then
fi
if | ; then
fi
Jan Tuomi