Posted on

Version Control Your Home Directory

Git is useful not only for working with software projects, but also for keeping a history of things in your home directory.  If you’re on Linux, then I recommend putting your entire home directory under Git. And if you’re on Windows, put the most appropriate directory under version control.

At first this may sound a little off the wall.

However, I am not recommending that you track everything.  In fact, I suggest that you very carefully pick and choose what you want to track.  This is what I did: after initializing the repository in my home directory, I opened the file .git/info/exclude and added this:

# Ignore everything
*

Which tells Git to ignore everything in my home directory.  Then after that I added specific rules to un-ignore the files I was interested in.  You can do this by prefixing the filename with the ‘!’ character.  For example:

# Ignore everything
*
# But save my Emacs files
!.emacs
!.emacs.d/
# And my Git config
!.gitconfig

And so on.  By doing this you can easily manage what Git tracks without creating a huge mess of your home directory repository.  Then you have all the benefits of using Git for things in your home directory, and can do stuff like push your home directory repository to one of our servers as a backup.