In an effort to minimize my downtime when the funny noises this MacBook Pro is making finally amount to something – I’ve wired up a git repository to OS X’s native launchd service. The git repository hold all of my active projects – whether development projects with their own repos, research projects, consulting project. Everything.
Right now, there’s a Mac mini holding the shared repo with a MacBook Pro and a MacBook Air pushing and pulling to it.
- Set up SSH keys the laptops and server (I like GitHub’s instructions)
- Set up the repo on the server
git --bare init
- set up a repo on both client macs
git add .
git commit -a -m "initial commit"
- create the active-projects.sh backup script in your ~/Documents directory
git pull origin master
git add .
git commit -a -m "Active Project Sync - $DATE"
git push origin master
- make active-projects.sh executable
chmod +x project-backup.sh
- Make the active-projects-backup.plist file for launchd
< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
- save the active-projects-backup.plist file to ~/Library/LaunchAgents and load it up
launchctl load ~/Library/LaunchAgents/active-projects-backup.plist
- Now, whenever a change is made in your ~/Documents/Projects – it will be automatically committed to the git repo and propagated to all computers connected to that repo. Like magic.
Thanks to culturedcode’s instructions for syncing Things with git & Launchd.
One Reply to “How to Automagically Sync Directories Across Multiple Macs with Git & Launchd”
Thanks for the tutorial on setting up git
I’m trying to follow the instructions to setup git auto sync on a couple of Macs and I have some questions. I think there might be some steps missing:
How is the server setup? Do I enable a Git service somewhere?
How do I connect the clients to the remote repo?
Is the LaunchDaemon for the server or the clients or both?
Does the LaunchDaemon run at intervals or when I write to the directory?
I would really appreciate if find the time to answer me, I’ve tried everything i can think of and I’m kinda stuck
Comments are closed.