Note on tracking dotfiles across multiple instances easily with git

< 1 min. read

Came across fast.ai’s dotfiles repo, which provided gems of insight into managing dotfiles in Linux (and Windows WSL) environment by using git bare repos. The repo also provided a very good quick start for some common command line configs. When you are working on various compute instances on cloud and/or on local, it is very handy to track and transfer dotfiles easily.

From scratch

Create an empty repo on Github/Bitbucket/Gitlab named dotfiles

git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc

git remote add origin https://repo/path/to/dotfiles.git

Add your dotfiles for example neovim and tmux:

config status
config add ~/.config/nvim/init.vim
config commit -m "add neovim"
config add ~/.tmux.conf
config commit -m "add tmux"
config push

Install on/migrate to new system

echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> ~/.bashrc
source ~/.bashrc
echo ".cfg" >> .gitignore
git clone --bare git@github.com:fastai/dotfiles.git .cfg/
config checkout
config config --local status.showUntrackedFiles no

Can customize by adding additional stuff like plugin managers Vundle or Plugged

# vim-plug
## neovim 
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

## vim
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

# Vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim