This post presents a "Pure Git" approach to managing dotfiles:
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:
git clone --bare MY_REPO_URL ~/.dotfiles cd ~/.dotfiles git config --local core.bare false git config --local core.worktree
git config --local status.showUntrackedFiles no git reset
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).
git reset --hard HEAD --
That's it, your home directory is now managed by Git!
cd to your
Run `git status` to see what has changed.
Note that all file operations have a `..` prefix
git add ../foobar
Use the following to manage your repo without having to
git --git-dir=$HOME/.dotfiles --work-tree=$HOME
You can add this to your `.bashrc` or `.zshrc` as follows:
alias dotgit="git --git-dir=$HOME/.dotfiles --work-tree=$HOME"
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!