Shing Lyu

Dotfiles: Manage Your Development Environment Configuration in GitHub

By Shing Lyu    

Disclaimer: The views expressed here are my own; they do not reflect the views of my current and past employers.

Linux is my major development platform. Most of the tool I use (vim, zsh, i3 window manager) use configuration files located in your home directory (.vimrc, .zshrc and .i3/config). It is pretty hard to keep them in sync between your machines. And sometimes if you mess up with the configuration file it’s pretty hard to revert your changes.

One day when I was looking for some vim configuration inspirations on GitHub, I stumbled upon a repository called “dotfiles” (I forgot whos repository it was), which contains all the configuration files in one repository. (In case you don’t know, It’s called “dotfiles” because most of the configuration filename start with a . so they are hidden.) This is actually a brilliant idea, by saveing your configuration files in a git repository, you get all the version control goodies. This aligns (kind of) with the DevOps concept of “infrastructure as code”. I would call it “development environment as code”.

There are many benefits of doing so. First, you can easily setup new machines by cloning the repository. Secondly, you have a full version control history of your configuration files, which makes it easy to revert changes or bisecting configuration errors. You can go back to a known good state when you mess everything up. You can also use git branches to manage machine specific settings. For example, you might want to have some special configurations in your office computers, which makes no sense in your home computer. In such situation you create two branches, one for your office machine and one for your home machine. You can still share common configurations between the two branches, while you keep the machine-specific part apart. Last but not least, by publishing your configuration files on GitHub, you can easily shared them with your friends.

Step-by-step Guide

Here are the exact steps to implement this method:

  1. Create a folder called dotfiles in your home directory.

     cd ~
     mkdir dotfiles
  2. Copy all you configuration files into the folder.

     cp .vimrc dotfiles/vimrc # Remove the dot so its no longer hidden
     cp .zshrc dotfiles/zshrc
     cp .i3/config dotfiles/i3config
  3. Remove the original configuration files, put softlinks in-place and point them to the files in the dotfiles folder.

     rm .vimrc 
     rm .zshrc
     rm .i3/config 
     ln -s dotfiles/vimrc .vimrc
     ln -s dotfiles/zshrc .zshrc
     ln -s dotfiles/i3config .i3/config
  4. Init a git repo, then add, commit and push your configuration files to GitHub. (Remember to remove any sensitive data like passwords, API tokens, personal information before you push.)

     cd dotfiles
     git init
     git add .
     git commit -m "Added my vimrc, zshrc and i3 config"
     # Setup your GitHub remote here
     git push 
  5. When you have a new computer you need to setup, git clone the repository and run the ln -s ... lines. Or you can put those lines in a shell script for one-click installation.


aptitude search '~i !~M' -F '%p' --disable-columns

(I use Debian-based Linux, but you can probably find similar command for other OS and package manager.)

Further Reading

Want to learn Rust? Check out my books:

Also available on O'Reilly and Amazon