How to Set Up Automatic Syncing for Obsidian Using GitHub for Free
This article explains how to automatically back up and sync your Obsidian Vault to GitHub for free. It also covers setting up GitHub on Kali Linux as a prerequisite and making your notes accessible via GitHub Wiki.
Note: If you work with a client, uploading data to a cloud service may not be allowed. Make sure to check the data handling policy.
Prerequisites
Install Git on Kali Linux
sudo apt update
sudo apt install git
Configure GitHub SSH Access
- Generate an SSH key:
ssh-keygen -t ed25519 -C "[email protected]"
Press Enter to accept the default file location and add a passphrase.
- Add your SSH key to GitHub:
Copy the public key:
cat ~/.ssh/id_ed25519.pub
Go to GitHub > Settings > SSH and GPG Keys > New SSH Key, and paste the key.
- Test the connection:
ssh -T [email protected]
- Add the SSH agent settings to
~/.zshrc
:if ! pgrep -u "$USER" ssh-agent > /dev/null 2>&1; then eval "$(ssh-agent -s)" > /dev/null fi ssh-add -l > /dev/null 2>&1 || ssh-add ~/.ssh/id_ed25519 > /dev/null 2>&1
Apply it:
source ~/.zshrc
Create a Private GitHub Repository
- Log into GitHub.
- Create a new repository and set it to Private.
Set Up Obsidian Vault Backup
Initialize Git in Your Vault
- Navigate to your Obsidian Vault:
cd /path/to/ObsidianVault
- Initialize a Git repository:
git init
- Add the GitHub remote:
git remote add origin [email protected]:username/repo-name.git
- Create a
.gitignore
file to exclude unnecessary files:echo ".obsidian/cache/" >> .gitignore echo ".obsidian/workspace" >> .gitignore echo ".obsidian/plugins" >> .gitignore
First Commit and Push
- Add all files:
git add .
- Commit the changes:
git commit -m "Initial commit of Obsidian Vault"
- Push to GitHub:
git branch -M main git push -u origin main
Automate Syncing
Create a Sync Script
- Create a file named
sync_obsidian.sh
:vim ~/sync_obsidian.sh
- Add the following script:
#!/bin/bash VAULT_DIR="/path/to/ObsidianVault" cd $VAULT_DIR git pull --rebase git add . git commit -m "Auto-sync: $(date)" git push
You can download the refined version of this script from my GitHub: sync_obsidian
- Make the script executable:
chmod +x ~/sync_obsidian.sh
Automate with Cron
- Open the crontab editor:
crontab -e
- Add a cron job to sync every hour:
0 * * * * ~/sync_obsidian.sh
Add Notes to GitHub Wiki
Clone the Wiki Repository
- Clone the GitHub Wiki repository for your project:
git clone https://github.com/username/repo-name.wiki.git ~/ObsidianWiki
Sync Markdown Files to the Wiki
- Use
rsync
to copy Markdown files from your Obsidian Vault to the Wiki repository (excluding unnecessary files):rsync -av --exclude=".obsidian" --exclude="*.jpg" --exclude="*.png" /path/to/ObsidianVault/ ~/ObsidianWiki/
- Commit and push the changes to the Wiki:
cd ~/ObsidianWiki git add . git commit -m "Sync notes to GitHub Wiki: $(date)" git push
Access Notes via GitHub Wiki
Navigate to the Wiki tab on your GitHub repository to view and read your synced notes.
Verify Syncing
Make changes to your vault in Obsidian.
Wait for the cron job to run or execute the script manually:
~/sync_obsidian.sh
Check your GitHub repository and Wiki to confirm changes are backed up and visible.