On my development computer I've previously used git simply as an automatic backup / recovery system. I know this isn't quite how git is intended to be used, but it has been very effective for me. I have a simple script that runs every 5 minutes (a la Windows Task Scheduler) and checks to see if any files have changed. If so, it creates a new commit (with the message "Automatic Commit") and pushes it to a mirror I have on an external hard drive. I can extend this to push to mirrors in other locations, too.
I don't want to stop doing this, as the system has saved my life more than once. Between power failures, accidental file deletions, or a client suddenly deciding they liked how the project looked 2 months ago and they want to revert all the changes - the ability to roll everything back to any point in time has been invaluable.
Now the problem comes when I want to put one of these repositories on github for collaborative work. Every time I push to github it creates tens or hundreds or commits, often with incomplete code since I was in the middle of modifying a file when five minutes rolled around.
I would like to have a second repository of sorts residing in the same directory and watching over the same files, however I want it to only commit manually. This way when I push to github there are only meaningful commits and all my automatic backups are hidden from prying eyes.
Is this even possible?
Quick Edit -
Googling around, could the git rebase
command be of any use? It seems like it may destroy all the automatic commits, which isn't exactly the ideal behavior.
Long Edit -
This little project has been a NIGHTMARE.
Following the advice from @janos I set set up a second repository in every folder. To set these up I simply used git clone
on the current repository. I modified my autosave.bat
file to utilize GIT_DIR
and GIT_WORK_TREE
and thought everything would be dandy... it wasn't
First, try the following on a Windows 7 PC for fun:
test.bat
--------
CD C:\SomeFolder
FOR /D %%i in (*) DO (
CD %%i
set GIT_WORK_TREE=%cd%
echo %GIT_WORK_TREE%
CD ..
)
The results of this should be obvious, right? We step through every sub-directory in SomeFolder
, set it to the current GIT_WORK_TREE
, then output GIT_WORK_TREE
. The output:
C:\SomeFolder
C:\SomeFolder
C:\SomeFolder
C:\SomeFolder
....
It looks like batch scripts are executed out-of-order (set GIT_WORK_TREE=%cd%
is processed before CD %%i
has completed). You can only imagine the horror this wreaked on my backups when every single project was in every other project's repository.
I tried to get around this using git --git-dir=backup.git --work-tree=%cd%
only to get errors when folders had a space in the name (I had to put %cd%
in quotes)
I finally got that working and backup.git
wasn't recognized as a git directory and was added to the repository! I added the following to my .gitignore to be safe:
# git is really making me angry today
/.git/
/backup.git/
With that I think it's finally working, but I shudder to test my remote backups and see if they're actually set up correctly.