Can I store the .git folder outside the files I want tracked?
git
Solution
git --git-dir=../repo --work-tree=. add foo
This will do what you want but will obviously suck when you have to specify it with every git command you ever use.
You can export `GIT_WORK_TREE=.` and `GIT_DIR=../backup` and Git will pick them up on each command. That will only comfortably allow you to work in a single repository per shell, though.
I’d rather suggest symlinking the .git directory to somewhere else, or creating a symlink to the .git directory from your main backup directory.
Problem
I have an unusual idea to use git as a backup system. So let's say I have a directory ./backup/myfiles and I want to back that up using git. To keep things clean I don't want to have a .git directory in the myfiles folder, so I thought I could create ./backup/git_repos/myfiles. From looking at the git docs, I've tried doing this: ``` $ cd backup/myfiles $ mkdir ../git_repos/myfiles $ git --git-dir=../git_repos/myfiles init Initialized empty Git repository in backup/git_repos/myfiles/ $ git --git-dir="../git_repos/myfiles/" add foo fatal: pathspec 'foo' did not match any files ``` You can see the error message I get there. What am I doing wrong?