There are a lot of dotfile managers out there like chezmoi, stow, yadm, and plenty more I’m sure. They each solve the problem of sharing configs in different ways, but they all require some kind of tool to be installed and some commands to be learned.
But you don’t really need any of these to have versioned and syncronized dotfiles, just git
.
git
tracks everything by default, so I just flip the logic. I simply ignore everything using a .gitignore
in my home directory, then force-add the files I actually want by hand, like so:
git init
echo '*' > .gitignore
git add -f .gitignore # the -f forces the file to be added even if it is ignored
This creates a new repo, sets up a .gitignore
to ignore every file, then force-adds the .gitignore
into the directory. All you need to remember is to force-add any dotfile you want to track:
git add -f ~/.bashrc
git push
If git add -f
is hard to remember, you can of course add an alias:
alias track-file='git add -f'
track-file ~/.bashrc
Adding Your Dotfiles to Another Machine
Let’s pretend you just bought another new laptop. This is how you bring your dotfiles down into the new machine:
(setup git)
git init
git remote add origin git@github.com:yourname/dotfiles.git
git pull origin main
No tools to install. No extra commands to remember. Just use git
.
Machine-Specific Configs
Different machines sometimes need machine-specific dotfiles. I handle this with simple host-based conditions in my .zshrc
(or .bashrc
) dotfiles:
if [[ "$(hostname)" == "work-laptop" ]]; then
source "$HOME/.zshrc_work-laptop"
fi
You already know everything you need to know to manage your dotfiles.