This post presents a “Pure Git” approach to managing dotfiles:
- No symlinks,
- No scripts,
- Just Git configuration.
It is inspired by a comment on Hacker News.
How it works
The dotfiles repo is cloned to
~/.dotfiles, but Git is told that
the working directory is the home directory.
From then on, it’s just a Git repo.
You can add any file in your home directory or subdirectories below it.
You could clone someone else’s dotfiles, but I advise against it - it’s best to understand what you have by stealing here and there.
Create your Dotfiles Repo
- Create an empty Git repo somewhere (I use GitLab),
- Follow the next section.
It is a good idea to add a
README file to the root of your repo with a copy
the setup steps below. That way, you know where to look every time
you need to set up on a fresh computer.
Install your Repo
If you’re installing on a new computer, you can do the following:
1 2 3 4 5 6
These steps have cloned and set up the Git repo, but so far nothing has changed.
Now, run the following to check what will change when you “install” the dotfiles:
Check you are not going to overwrite any local files with local changes you want to keep.
Beware - the next line installs the current version of files in your dotfiles repo, potentially overwriting different versions in your home directory (or subdirectories).
That’s it, your home directory is now managed by Git!
cd to your
git status to see what has changed.
Note that all file operations have a
Outside the .dotfiles directory
Use the following to manage your repo without having to
You can add this to your
.zshrc as follows:
If you add that to your dotfiles repo, that’s really all the configuration you need.
The is no
.gitignore in this system, as Git is instructed to ignore all
files that are not part of the repo.
If you want to automate adding local changes to your repo, it should be quite easy. Though, you’ll need to decide how to deal with remote changes if you are using your dotfiles on more than one computer.
If you have big differences between your needs on your various computers, you can even keep differences in branches!
Enjoy your lightweight dotfiles!