Published at
Updated at
Reading time
1min

My dotfiles are powering multiple machines, and overall I've been happy with them. They include hand-written shell scripts to create symlinks, download all desktop apps and CLI tools, and get my preferred system settings in place. But overall, they've become a Frankenstein over time because many random scripts are doing random things. And obviously, I failed to document what's going on properly.

Sure, scripts have to run to install stuff, but for config file management, most solutions I've seen seemed too complicated to keep some files in sync. And I really don't want to use a dotfile framework to pull some configuration files.

What if there is a way to tweak Git and track all the .*rc and config files?

"Dotfiles management" describes Git magic to track all files somewhere on your machine from a single .git repository. Yes, your read that right. Any file and anywhere.

alias dotfiles='git --git-dir=/home/mx/.dotfiles --work-tree=/'

That's right; there's a .git folder somewhere on your machine (/home/mx/.dotfiles in the example), and it'll track all the files no matter where they're located, thanks to the --work-tree argument. Then there's no symlink dance!

With some additional configuration, you can add and sync files across machines without scripts using dotfiles add or dotfiles commit. It's all just plain Git.

This dotfiles approach is by far the smartest I've seen, and I'll definitely give it a shot when I fiddle with my system config the next time.

If you enjoyed this article...

Join 5.5k readers and learn something new every week with Web Weekly.

Web Weekly — Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles