11

I would like to track my $HOME dir with git. I've got many other git repos in other subdirs (eg $HOME/projects/repo_1 and so on), which shouldn't be tracked, since they already are.

I have found git-home-history but it appears from the archive that the project is no longer actively developed.

What approach do you recommended? Is ghh mature enough?

I am on a Mac but I am interested in cross platform solutions, too.

Thanks

ps: I have looked but didn't find duplicates, please point them out if this has already been discussed.

udo
  • 8,061
Francesco
  • 674

3 Answers3

5

I've been doing this for a while just using git. I don't track the entire home directory, just the parts that I am actively changing. This includes my home/bin directory, which contains lots of little scripts, my .vim directory, and some larger projects in other directories. Also there are some configurations for terminals and openbox, as well as various other apps, added to the repo.

This works well enough since all of this stuff has the same permission set and I don't care about the original timestamp. It's getting to the point where I'm planning to break some of it out into submodules using git filter-branch. This is a bit tricky though since there are interdependencies between files in different subdirectories (eg some .vim scripts might call scripts from my bin directory... not a very good example but hopefully you get the point).

I haven't found any more comprehensive solutions, but also haven't really looked into any, including git-home-history. It seems like it would be pretty complicated to put the entire home directory under revision control, and there would be a lot of variables. For instance if you put your firefox profile(s) under revision control, you're going to end up piling up huge amounts of binary differentials. Also there are things like ssh keys that are often better lost than duplicated.

If you do want to track permissions (other than the executable bit, which git already tracks) there is apparently a hook that will do that. It's mentioned in this serverfault thread.

intuited
  • 3,481
0

You can use git on your home directory, then use git submodules or revise-tree for the external git projects that you work on.

edgester
  • 182
0

So, first thing first, I am not trying to backup home in general.

Under Linux or macos, I only want to track some of the ~/.xxx config files, without interfering with, or caring about, lower level repositories, files or directories.


First things first, create the repo:

cd ~
git init

In the past, I did that and ended up with a very "noisy" git repo that was always either complaining about untracked files or about lower level repos that it was not tracking. Yes, submodules can probably help, but they seem overkill here.

So, second thing is to tell it to ignore everything! via .gitignore:

~/.gitignore
.*/*
*

At this point, it is not tracking anything and git status will show nothing going on. It will even actively refuse to add files for tracking (git add foo<tab> will not autocomplete for example).

Now, you can add selectively add only the configuration files you want to backup.

git add -f ~/.wezterm.lua

where -f is the force flag to tell to ignore your .gitignore

And if you want to know what is being tracked in git (since it will silently ignore everything):

git ls-tree -r $(git branch --show-current) --name-only

giving:

.bashrc
.config/Code/User/settings.json
.config/Code/User/snippets/dot.json
.config/Code/User/snippets/html.json
.config/Code/User/snippets/markdown.json
.config/Code/User/snippets/python.json
.config/Code/User/snippets/shellscript.json
.config/dconf/user
.config/mimeapps.list
.gitconfig
.inputrc
.profile
.wezterm.lua
.zshrc

JL Peyret
  • 884