If you haven’t been tracking your dotfiles before, believe me you should definitely start do so right away. I’m preaty sure you’re also one of those guys who has always been quite annoyed by managing dotfiles. But hey, it’s never too late, so get your hands dirty and avoid of crying over lost dotfiles.

Getting started with storing dotfiels in a git repository

  • Create a git bare repository at ~/.dotfiles to track files

git init --bare $HOME/.dotfiles

  • Add alias to shell configuration file in my case it’s .zshrc

echo 'alias dotfiles="/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME"' >> $HOME/.zshrci

  • Reload the shell

source ~/.zshrc

  • Prevent untracked files from showing up on dotfiles status

dotfiles config --local status.showUntrackedFiles no

Add, commit and push dotfile

This way you can add, commit and push dostfiles from any directory to remote repo in git using dotfiles alias.

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

Install dotfiles to a new system

  • Create alias in the current shell

echo 'alias dotfiles="/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME"' >> $HOME/.zshrc

  • Reload the shell

source ~/.zshr

  • Add .dotfiles directory to .gitignore file to avoid of any errors

echo ".dotfiles" >> .gitignore

  • Clone the repo

git clone --bare https://www.github.com/vladhor/repo.git $HOME/.dotfiles

  • Checkout the content

dotfiles checkout

  • Prevent untracked files from showing up on dotfiles status

dotfiles config --local status.showUntrackedFiles no

Bear in mind, that in case you already have dotfiles with identical names, checkout will fail with an error. Back them up and repeate step, or just skip back up if you don’t need them anymore.