How to manage your dotfiles with git

Flavio Wuensche
Oct 14, 2016 · 2 min read

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 so 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
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.


Movido a pessoas incríveis — A Touts é uma plataforma…

Flavio Wuensche

Written by

Software Engineer at Doctolib — the #1 booking platform and management software provider for doctors in Europe



Movido a pessoas incríveis — A Touts é uma plataforma dedicada a apoiar a expressão de pessoas incríveis de todo o planeta. Toda compra alimenta uma paixão e possibilita o criador a compartilhar seus trabalhos com o mundo e com você ;)

More From Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade