Git is a relatively new Version Control System, initially started by Linus Torvalds in order to manage the source code of Linux Kernel.
Although Randal Schwartz has stated that Git was not designed to version your home directory, it seems that many people are now trying to do so :-)
Some people have used CVS or Subversion for this purpose in the past, but to my mind, Git is suited better for this task for several reasons:
- Git is grep-friendly (only stores it's metadata in a single .git directory at the root of working copy)
- It is very easy to work with a local repository (just do git init and you're ready)
- Git stores changes very efficiently (even binary files), so not much disk space is wasted, but don't forget to call git gc from time to time
- Git repository is always available on your computer, even when you are offline, but on the other hand it is very easy to push your changes to a remote repository as well
Having said that, my setup is ultra-simple compared to others on the net!
To start versioning your home directory, just run this in the root of your home:
git initThis will initialize an empty local Git repository in ~/.git/ - this is the location that you can use when doing backups, but otherwise you shouldn't care about it anymore.
Then you need to tell Git to track your important files:
git add DocumentsThen you can work normally with your tracked files and occasionally commit your changes to the repository with
git add bin
git add whatever else you want to version
git commit -m "Adding initial files"
git commit -a "description of changes you have done"Note the "-a" above, that means to commit any changes made to any previously tracked files, so you don't have to use git add again. But don't forget to git add any new files you create before committing.
Use git status to show what files were changed since your last commit. Unfortunately, it will also list all untracked files in your home directory, so you may need to create a .gitignore file. You can get the initial version of this file using this command:
git status | awk '/#/ {sub("/$", ""); print $2}' > .gitignorethen, edit it and possible replace some full names partly with '*'. Don't forget to git add and git commit this file as well!
That's, basically, it! You may also try some GUI tools provided by git, eg gitk or git gui to browse your changes and do some changes if you can't remember the commands.
Moreover, I have some more ideas how to make all this more automatic that I am going to try laster:
- Put git commit -a to user's crontab in order to commit changes automatically, eg daily
- Create a couple of nautlus scripts (located in ~/.gnome2/nautilus-scripts) to make adding, comitting and other actions available directly from Nautlilus file manager in Gnome.