How to manage your dotfiles with git

Flavio Wuensche
2 min readOct 14, 2016

Based on a Hacker News solution proposed by StreakyCobra

In his own words, some advantages of this approach are:

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.

Getting started

If you're starting from scratch, go ahead and…

  • create a .dotfiles folder, which we'll use to track your dotfiles
git init --bare $HOME/.dotfiles
  • create an alias dotfilesso you don't need to type it all over again
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
  • set git status to hide untracked files
dotfiles config --local status.showUntrackedFiles no
  • add the alias to .bashrc (or .zshrc) so you can use it later
echo "alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'" >> $HOME/.bashrc


Now you can use regular git commands such as:

dotfiles status
dotfiles add .vimrc
dotfiles commit -m "Add vimrc"
dotfiles add .bashrc
dotfiles commit -m "Add bashrc"
dotfiles push

Nice, right? Now if you're moving to a virgin system…

Setup environment in a new computer

Make sure to have git installed, then:

  • clone your github repository
git clone --bare $HOME/.dotfiles
  • define the alias in the current shell scope
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
  • checkout the actual content from the git repository to your $HOME
dotfiles checkout

Note that if you already have some of the files you'll get an error message. You can either (1) delete them or (2) back them up somewhere else. It's up to you.

Awesome! You’re done.

I regularly share short articles about React and Rails development. If that’s of value to you, follow me on twitter and hit that subscribe button below 💥

Flavio Wuensche

Write about React and Rails. Building an open-source tool to keep track of technical debt on large codebases 🍒