Store dotfiles in a bare git repo

Updated: 08 April 2024

See https://www.atlassian.com/git/tutorials/dotfiles
See https://news.ycombinator.com/item?id=11070797

Create a bare repo in directory dfs

git init --bare $HOME/dfs/.gitdfs

Create a handy alias in your .bashrc file

gitdfs='git --git-dir=$HOME/dfs/.gitdfs --work-tree=$HOME'

Set a flag for this repo only, which hides untracked files

gitdfs config --local status.showUntrackedFiles no

Now, any file in $HOME can be versioned with normal commands

gitdfs status
gitdfs add .vimrc
gitdfs commit -m "Track my .vimrc file"
gitdfs push

Show the files tracked so far

gitdfs ls-tree -r the_branch --name-only

Leave a comment