Guilherme Ramos

Guilherme Ramos

Software Developer

Configuring a version control for my Obsidian vault with GitHub, bash scripts and cron

25 de maio de 2025

Configuring a version control for my Obsidian vault with GitHub, bash scripts and cron

How did I resolved a annoying situation with Git, bash scripts and cron

obsidianbashcroncode

Intro

Some time ago, I started using Obsidian. It’s probably my third or fourth time trying it out while exploring other options like Notion, AnyType, and Craft. But I’m not saying something like “this time it will be different,” because I’d feel guilty - or afraid of being judged in the future - if I decided to switch to another tool (which isn’t impossible, by the way). So instead of making that kind of promise, I’ll just say the main reason I chose Obsidian: you have full control over your files.

Instead of having everything stored on someone else’s server, your files are saved on your own computer, and you can configure backups however you want. Having full control over my notes was important because I wanted the freedom to back them up, store personal info, etc., without worrying that this data would sit on someone else’s server — or that the company might go under and I’d need to download everything and migrate elsewhere. That’s why I chose Obsidian.

I’m not 100% familiar with it yet and I’m still exploring how to do some things. Recently, I accidentally deleted some files without noticing (I was careless — I admit it). Luckily, they were still in my bin folder. But the idea of deleting something without a way to recover it later felt scary. So I decided to implement version control myself. I’m not sure if Obsidian has this natively (I saw they offer a paid backup system), but I wanted to do it manually using GitHub. It didn’t seem too hard, so I gave it a shot.

My idea was:

  1. Turn my vault into a Git repository;

  2. Store it on GitHub;

  3. Create a Bash script that checks for changes in the vault — if there are any, it commits and pushes them; otherwise, it does nothing;

  4. Set up a cron job to run the script periodically.

Creating the Bash Script

First, I ran git init inside my vault to turn it into a Git repository. Then I created a new repository on GitHub and added it as the remote for my local repo. So far, so good.

Then I wrote the Bash script, which looked like this:

#!/bin/zsh

cd ~/Documents/my-vault/
# Run a `git diff` and store the result in a variable called `diff`
diff=$(git diff --name-only)

# Check if `diff` is empty
if [ -z "$diff" ]; then
    echo "No changes detected, exiting..."
    exit 0
else
    echo "Changes detected, syncing..."
fi

# Stage all changes
git add .
# Commit the changes with a timestamp message
commit_message="syncing_vault_$(date +%s)"
git commit -m "$commit_message"
# Push to GitHub
git push origin main

Here’s a breakdown: the script navigates to the vault folder, checks for changes, and exits if none are found. If there are changes, it stages everything, commits with a timestamp, and pushes to GitHub.

Pretty simple, right? But running it manually every time I make changes would be boring — and honestly, I’d probably forget. That’s not safe. So I decided to run it automatically every 10 minutes using cron.

Configuring a Cron Job

To run the script every 10 minutes (this is an arbitrary value, I could have set to any other interval), I needed a cron job. I wasn’t sure how to set one up on macOS, but a quick Google search led me to this article, which had everything I needed. I ran crontab -e and added the following line:

*/10 * * * * ~/scripts/sync-vault.sh >> ~/cron-sync-vault.log 2>&1

*/10 * * * * means the script will run every 10 minutes. >> ~/cron-sync-vault.log 2>&1 logs the output to cron-sync-vault.log, which is useful for debugging (I might delete it later or write another script to clear it daily — still undecided).

And that’s it. Now I have version control for my Obsidian vault, fully DIY.

Conclusion

This is a pretty simple solution to a pretty simple problem. Even though there’s probably a ready-made solution or plugin out there, I wanted the challenge of building it myself — just for fun. It’s how I keep my brain working in this AI-driven era.

If you know a better or simpler way, reach out to me on LinkedIn — let’s share knowledge. I hope this helps someone or sparks a conversation. See ya, folks.