I like Live Mesh. I like Git, too.

If you’ve used a folder synchronizing tool before that will propogates file changes between machines, like FolderShare or DropBox, there’s a good chance you’ve had a scare with some possible data loss. Maybe you accidentally dropped a folder into a subfolder, “made space” by getting rid of files on one of the machines, or the sync software went crazy. Whatever the case is the change is immediately shipped onto all of your backups all over the world.

That effect makes file sync tools more of a convenience than a backup strategy – it can lower your mean time to recovery in case of hardware failure – but even though there are two or more physical copies of your bits there’s really one logical copy that appears in several places where it can be accidentally deleted. Ironically the convenience of having your data everywhere also lowers it’s mean-time-to-accidental-destruction.

Which is exactly the problem a change control repository like Git is designed to solve! Fearing data loss as much as the next person, I tried to combine the convenience of Live Mesh with the safety of Git and it worked really well. Here’s how it went, assuming you have msysGit and Live Mesh installed on your machine.

Update here’s a diagram of what we’re ultimately going to try to accomplish.

livemesh

Initialize Git

First off – the goal is not to put a Git repository into a Live Mesh folder. Git already has a push-pull mechanism to move changes around and the word is Live Mesh will just trash your repos files by moving overlapping changes over each other on different nodes. Instread what we’ll be doing is creating a new Git repository and using a Live Mesh folder as it’s working copy.

:create a new folder to hold files
mkdir "%userprofile%\Documents\Junk Drawer"

:go to it
cd "%userprofile%\Documents\Junk Drawer"

:initialize a repository
git init

:mark the .git subfolder hidden
attrib +H .git

Or if you prefer to avoid command-line you can do the same thing with Git GUI and Explorer.

git-gui-here

create-new-repository

git-folder-properties

Initialize Live Mesh

Then the magic happens – add the Junk Folder to Live Mesh.

add-folder-to-live-mesh add-folder

Throw some files in there and they’re automatically synchronized onto Live Desktop online (and to other devices which you have synchronizing the Junk Drawer). The Live Desktop gives you a browser-based Explorer-like interface to your files.

live-desktop

You can now access and modify the files in the Junk Drawer from any number of devices, including downloading and uploading files through mesh.com. All changes will be synchronized at every location including the one we originally created which is the working directory of the Git repository.

Commit Changes

commit-changes Git keeps track of your files in the working folder when you select the changes to stage, provide a comment, and hit commit. Because it’s all synchronized it doesn’t matter which device caused the changes. There are plenty of Git tutorials out there so I won’t go through all the steps of adding files and committing them, looking at history, restoring files from source control. In the end the point is that this Git repository is now providing change control tracking for my Junk Drawer folder and (by extension) all devices on the Mesh hosting that folder even if they don’t know it.

Push Changes

If we stopped here there would be a history and some protection against accidental deletion (because you can get the files out of Git if they disappear) but there’s still a risk we’re exposed to. All of the repository data is saved in the hidden “Junk Drawer\.git” folder which could be lost if the drive fails or if the Mesh goes insane and wipes out the entire Junk Drawer parent folder.

Fortunately it’s a really easy problem to take care of – from this git repository simply initialize a new remote repository and push all changes to it. Okay, maybe it’s a little tricky to get set up because msys and git are a bit… awkward… when it comes to drive letters and such. So here are the commands you’ll use to create a remote repos on a known UNC.

:map a drive long enough to initialize an empty repository.
:use whatever unc and drive letter is appropriate for you
net use G: \\10.0.0.3\storage

:go into the working folder
cd "%userprofile%\Documents\Junk Drawer"

:and create a bare repository on the file server
:use whatever folder name makes sense
:the foldername.git extension is conventional for Git repositories
:that don't have a working copy of the files checked out
git clone --bare . G:/junk.git

:unmap the drive letter
net use /delete G:

:inform the local repository that "origin" refers to this new unc git location
git remote add origin //10.0.0.3/storage/junk.git

:and finally push over to the "origin" repos everything on the default "master" branch
git push origin master

Once the association between the local and remote repos is established you can push to it from Git GUI any time you commit changes on your mesh.

push-branches

Conclusion
And there you have it!

* You can have a Live Mesh folder synchronized between any number of devices.
* Each device can create, access, and modify those files normally without being aware of change-control
* You can commit changes on your mesh folder into a Git repos exactly as if it was a working folder
* You can push commits to an even more rugged Git repos on a distinct and isolated storage location

And now your files are safe – even if Live Mesh goes completely insane destroying all of your files and the hidden .git folder inside the original device’s Live Mesh folder. All you need to do is clone the Git repos down from the storage location back onto your hard drive and you’ll have all of the changes you pushed earlier in a new local repos and a rebuilt working folder filled with all of your files. Mark the new .git folder as hidden again, add the working folder back into Live Mesh, and you’re up and running again.