How I Manage My Dotfiles

1. What is dofiles

The definition by archlinux, User-specific application configuration is traditionally stored in so called dotfiles (files whose filename starts with a dot). Some of them listed below:

  • .vimrc
  • .tmux.conf
  • .gitconfig
  • .ssh/
  • .aws/
  • .gnupg/
  • .config/

Those dotfiles are all located in your home directory.

2. Best way to manage dotfiles

Bare repository and alias method is the best way to keep track of changes and synchronize your dotfiles between hosts.

git init --bare ~/.dotfiles
alias got='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
got config status.showUntrackedFiles no

and then you can manage your dotfiles with alias command got just like use git command.

Now you can manage your dotfiles with git and you may push your repository to github.com. And you want to shared your dotfiles with others, so you have to make your repository public on github. Hold on! what about the files in directory like .ssh/, they can’t be made public.

3. How to manage the secrets of dotfiles

Some of dotfiles can be made public (.vimrc, .tmux.conf etc.) and the others only known by yourself (.ssh/ .aws/ etc.). We can use gnupg and a private git repository to manage them.

First thing you need to do is, create a separate directory to store those secret files and initialize it as a private git repository on your github account. In my case, I created a directory in my home directory named ~/.secrets/data.

Then use gpg command encrypt your secret files into ~/.secrets/data, after that you can push it to remote. When you need those files to be up to date in other host, you can checkout this private repository. (the best way is made this repository as a submodule of your dotfiles repository.) use gpg to decrypt secret files back into their original location.

I have written two scripts named encrypt.sh and decrypt.sh (can be found in my dotfiles repository) to automatically compelte this process

That’s all. you can easily manage your dotfiles in a happy way.

References


Last modified January 5, 2022: Docsy Theme (efcef74)