Obsidian sync with Github and Crontab
Create your own repository on Github
Create new private repository on Github.
Create the Obsidian vault
Create you new vault in Obsidian.
Initialize git
Locate at Obsidian vault, Initialize git in local folder
git init
Add .gitignore
in the vault
First commit
Add all files to the track of git
git add .
Write the commit
git commit -m "<init><notes>"
Push the commit to the remote branch
git push
sync shell
In the sync.sh
write up your sync shell.
#!/bin/bash
# Generate commit message automatically
gstatus=`git status --porcelain`
if [ ${#gstatus} -ne 0 ]
then
git add --all
# sleep 10 seconds
sleep 10
git commit -m "$gstatus"
sleep 10
git pull --rebase
sleep 10
git push
fi
I use the shell from here.
You have to give execute permission to sync.sh
to avoid permission denied.
chmod u+x sync.sh
Crontab
Set up
Set up crontab:
crontab -e
And use the follow script to run the script every 5 minutes.
Check crontab guru to know crontab expression.
# Sync Obsidian vault
*/5 * * * * cd /Users/minhanhuang/Documents/vaults/ && sh /Users/minhanhuang/Documents/vaults/sync.sh
Full Disk access for cron
Add cron to full disk access to avoid permission denied when running shell.
Command + shift + G
and go to /usr/sbin
Drag cron into Full Disk access.
log
To check your sync shell is working properly, cat mail log at:
cat /var/mail/${username}
After finished sync setup, you are able to sync Obsidian notes automatically with Crontab and Github.
comments powered by Disqus