How to manage your dotfiles with git
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
dotfiles
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
Usage
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…