05 Jun 2022

How to manage your dotfiles with git

Category howto
Tags #linux #git

How to manage your [dot] files with git. First of all what is dotfiles ? For those who don’t konw dotfiles is configuration files inside your home directory file names and directories starts with a “.” thats why it’s called dotfiles.

The problem ?


I’ve started search for solution and it gets me to this article Method it self as it mention in article has been proposed on hacker news

it was simple and plain in terms of linux way

Step 1

Choose directory where your repository will be stored for instance ~/Dotfiles

Step 2

Got inside and make git bare repostory

cd ~/Dotfiles

git init --bare .

Bare repository is repository without a working directory so it’s contains of git internals structure itself to store objects added to repostory

You better know what is bare git repository here

Step 3

Setup special alias for git command to work with ~/Dotfiles

alias dotfiles='/usr/bin/git --git-dir=$HOME/Projects/Personal/Dotfiles/ --work-tree=$HOME'

Make this alias permanent by adding it to your .bashrc or .zshrc configuraton

Step 4

Make git stop showing untracked files

dotfiles config status.showUntrackedFiles no

Step 5 Finally

dotfiles add ~/.zshrc

dotfiles -m "Add zsh configuraton"

That’s it. If you want to push to remote add origin before and push it same way

dotfiles add origin URL

dotfiles push origin master

Since dotfiles is special alias for git you can do dotfiles status when editing your configs to see what files have been changed.

Why this is good solution ?

If you’re mind to store configs as usual and just create simple directory to store it, you have to deal with setup process to actually update files on their location in system, using this method you don’t need to think about install and deploy.

When you do dotilfes ls you don’t have to deal with other files which is not been added to repository and are not dot files you’re interested in.