In Unix-based Operating Systems, we configure most applications with
text-based configuration files (e.g.
.tmux.conf for tmux,
for emacs). How to backup these text-based configuration files–the
dotfiles–and restore them subsequently is an usual concern that I
In this post, I describe my system for backup and restoring my dotfiles.
I have three basic requirements for such a system:
- it must allows me to quickly setup a new computer;
- it has minimal dependencies;
- it can be version controlled easily, ideally via git.
While these are relatively simple requirements, suprisingly, I was not able to find a good solution for a long time. Two solutions I have tried but did not work very well are:
- the manual method: copy and paste the dotfiles to and fro Dropbox;
- bare git repo method: see here.
Recently, I stumbled upon
stow and found
that it is the ideal solution. I will describe my dotfiles management
system later, after briefly showing you how
First we need to install stow with:
sudo apt install stow
Suppose you have the following file directory:
If you change directory to
dotfiles and run
What happends is that all files in the folder
app will be
the home directory
/home/hung with the same folder structure. In
this particular example, we will have a directory that look like this:
That all there is.
My dotfiles configuration system
My system relies entirely on
I store all dotfiles in a folder called
dotfiles in the
directory. For each application, I create a folder in
dotfiles with the same name,
and store all dotfiles of that application in this foler.
Notice that these dotfiles have to be stored in the same folder structure
as how they are used by the application.
Then, suppose I want checkout the
dotfiles for the application
<app>, I just do:
cd ~\dotfiles && stow <app> # <app> is emacs, vim, etc...
For my own dotfiles I create two shell scripts corresponding to two
modes. In the scripts different stow commands are ran, depending on
the particular mode. This structure also makes it trivial to version
all dotfiles using
git, backup and restore as you wish!
My own dotfiles live here [
free to take a look.