Having dotfiles from the $HOME directory in git is a great way to keep track of what’s going on with some of our most important config files.

However just creating a plain git repo won’t play nice with other repos found further down in the home tree. Chances are that at some point we’ll accidentally issue a git command on the home repo instead of the one we actually want to work on.

So why not make our own git command which handles the home repo exclusively. We’ll name this new command cfg an create an alias in ~/.bashrc for it.
Since we want git to use a special .cfg directory instead of the default one and still have the working tree set to $HOME the alias will look like this:

alias cfg='git --git-dir=$HOME/.cfg --work-tree=$HOME'

Now we can issue a git init command in the home dir. If you already have a .git directory you can just rename it to .cfg.
One tweak is configuring cfg not to show untracked files.

cfg config status.showUntrackedFiles no

If we want to be absolutely sure that we won’t mistakenly add files (like the Pictures directory), then we need to create a .gitignore file, either with each ignored directory on a new line, or with the wildcard symbol:


Now when adding files we have to issue a cfg -f add command.

And we’re done!