Manage dotfiles using a git bare repository

2020/01/01 by Paulo Pereira

~/categories/Linux #Linux #Arch Linux #Git #Keybase

I’ve been searching the best way to manage my dotfiles using git.

After seeing this video and checking this tutorial I decided to give it a go.

I will be using keybase as my (private) git repository.

Create and setup repository

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

Adding files

dotfiles status
dotfiles add .vimrc
dotfiles commit -m "Add vimrc"
dotfiles remote add origin keybase://private/your_username/dotfiles
dotfiles push -u origin master
dotfiles add .bashrc
dotfiles commit -m "Add bashrc"
dotfiles add .zshrc
dotfiles commit -m "Add zshrc"
dotfiles push

Dotfiles in a new system

alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
echo ".dotfiles" >> .gitignore
git clone --bare keybase://private/your_username/dotfiles $HOME/.dotfiles
dotfiles config --local status.showUntrackedFiles no
mkdir -p $HOME/.dotfiles-backup
dotfiles checkout
if [ $? = 0 ]; then
  echo "Checked out config.";
  echo "Backing up pre-existing dot files.";
  dotfiles checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} $HOME/.dotfiles-backup/{}
dotfiles checkout
dotfiles pull