The best way to store your dotfiles: A bare Git repository
Disclaimer: This post is heavily based on the one at https://www.atlassian.com/git/tutorials/dotfiles which goes more into the details
Some other sources you might want to check out:
- Hacker News thread on people’s solutions to store their dotfiles.
- User
StreakyCobra
showed his elegant setup
The only pre-requisite is to install Git.
In his words the technique below requires:
No extra tooling, no symlinks, files are tracked on a version control system, you can use different branches for different computers, you can replicate you configuration easily on new installation.
TLDR;
Store your dotfiles in a Git bare repository which acts as a “side” folder (like $HOME/.dotfiles
or $HOME/.myconfig
) using a specially crafted alias. This alias runs the git
-command against that repository and not the usual .git
local folder, which would interfere with any other Git repositories around.
Starting from scratch
Create a bare git repo in your home folder and define an alias to work with it:
|
|
After this you can manage every file within the $HOME
folder with the newly created dotfiles
alias, like:
|
|
Install your dotfiles onto a new system (or migrate to this setup)
If you already store your configuration/dotfiles in a Git repository, on a new system you can migrate to this setup with the following steps:
|
|
The step above might fail with a message like:
|
|
This is because your $HOME
folder might already have some stock configuration files which would be overwritten by Git. The solution is simple: back up the files if you care about them, remove them if you don’t care. I provide you with a possible rough shortcut to move all the offending files automatically to a backup folder:
|
|
Re-run the check out if you had problems:
|
|
- Set the flag
showUntrackedFiles
tono
on this specific (local) repository:
|
|
- You’re done, from now on you can now type
dotfiles
commands to add and update your dotfiles:
|
|
For completeness this is what I ended up with (tested on a freshly minted Alpine Linux virtualbox):
|
|
Wrapping up
I hope you find this technique useful to track your configuration. If you’re curious, my dotfiles live here. Also please do stay connected by following @cblte.
Bonus
To get the script from here into the Alpine virtualbox machine we use the help of the null-pointer from envs.sh
|
|