Consider one of the following scenarios: you lost your laptop. Your laptop is stolen. You clumsily dropped it on a marble staircase. The battery exploded. The battery didn’t explode, but it got hot, produced smoke, and you had to inform a member of the crew who sequestered your laptop and eventually stole it. A cosmic ray hit a specific bit of memory at a specific time that caused the entire system to wipe all data. All of the above. Or maybe, you just want a new laptop.
Whatever happens, I only know that what is important to me is to be able to regain a system that is equivalent to the one I just had as fast as possible. No interruptions, no time lost in setting preferences, aliases, dotfiles, ssh keys, etc.
In other words, I want my laptop to be fungible. At least concerning the system’s configuration. Only then I can achieve peace of mind, and therefore be prepared for any of those unfortunate eventualities to happen (which won’t, because I achieved peace of mind).
Thanks to git
, this is very easy to do, offline, and without the need to store any information through third parties.
The reason for that is something that perhaps is overlooked in the most typical use cases: the files tracked by a git repo can have arbitrary paths and do not need to share a parent directory with .git/
.
The following is the README of a git repository named .dotfiles. .dotfiles/
(which would be called .git/
by default) lives at an arbitrary location $GIT_DIR
and is synced somewhere else safe, such an another system or SSD device.
By reading the README in full, it should become clear how to use the .dotfiles repository and what to do to restore your original system configuration on a new machine.
To the future me who thought so exceptionally unlikely to have to change work latop just at that very inconvenient time: you’re welcome.
Install in a new system
Warning: this will overwrite existing .dotfiles on the new system. Consider making a backup before proceeding.
To port the .dotfiles from an old system to a new one, first sudo rsync -a
the content of .dotfiles
on the new system at $GIT_DIR
. Then, move to your $HOME
and restore the .dotfiles:
cd ~
GIT_DIR=$HOME/Xiv/software/repo/github.com/.dotfiles
sudo git --git-dir=$GIT_DIR --work-tree=$HOME restore .
Source ~/.bashrc
. This will also enable the dotfiles
alias defined below.
The dotfiles
command is used to interact with the .dotfiles repository independently of the current working directory, replacing the usual git
command:
source ~/.bashrc
Switch to the main branch:
dotfiles switch main
Everything is now in place in the new system. See the following section to keep the .dotfiles up to date.
Update .dotfiles
Use the dotfiles
alias to update the repository. For example, if you made changes to ~/.bashrc
:
dotfiles add ~/.bashrc
dotfiles commit -m 'added ~/.bashrc'
Note: dotfiles
is the chosen alias for sudo git --git-dir=$HOME/Xiv/software/repo/github.com/.dotfiles --work-tree=$HOME
If you wish to change the location of the --git-dir
, i.e. the location of .dotfiles/
, i.e. $GIT_DIR
, you need to update the dotfiles
alias and this README accordingly.
If dotfiles status
shows untracked files, run:
dotfiles config status.showUntrackedFiles no