Note on tracking dotfiles across multiple instances easily with git

Came across’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 .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 \

## vim
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \

# Vundle
git clone ~/.vim/bundle/Vundle.vim

Handling line endings on Windows with git

Note to self: When collaborating on different platforms, one of the most common issue is line endings – LF on Mac/Linux and CRLF on Windows. With git, you can address this issue in the following ways:

1) Configure Global Settings

1) Windows users: git config --global core.autocrlf true
2) Mac/Linux users: git config --global core.autocrlf input

2) Configure Per-repository settings

echo "* text=auto" > .gitattributes
git add .
git commit -m "Files play nice in Mac, Linux and Windows"
git push origin master

Additional reading:
StackOverflow thread
Github help