Obsidian is a great note-taking app that I use for my personal notes. I have been using it for a while now and I have a lot of notes that I want to keep private. I also want to sync my notes across my Linux and Android devices.
First I initialized a git repository in my Obsidian vault folder. And pushed it to a private GitHub repository git@github.com:jahangir1x/obsidian-vault.git
A typical obsidian vault has .obsidian
folder that contains the configuration and metadata of the vault. I have created a bash script sync.sh
that will sync the vault with the GitHub repository.
contents of sync.sh
:
#!/usr/bin/env bash
# get directory of this script and cd to ../
cd "$(dirname $(dirname ${BASH_SOURCE[0]}))"
echo "[+] pulling from remote..."
git pull
echo ""
if [ -n "$(git status --porcelain)" ]; then
echo "[+] changes detected, pushing to remote..."
git status
echo ""
git add .
git commit -m "sync client: $(whoami)@$(hostname)=>$(uname -o)"
echo ""
git push
echo ""
else
echo "no changes to push."
fi
cd "$(dirname $(dirname ${BASH_SOURCE[0]}))"
will cd to the directory of the vault. So, I can run the script from anywhere.
I don’t care about the commit messages, so I just use the id, hostname and the OS name
as the commit message. So, I can see which device made the last change.
In my Linux .zshrc
I have added an alias to run the script:
obsidian-sync() {
bash ~/obsidian_vault/.obsidian/sync.sh
}
Now I can run obsidian-sync
from anywhere to sync my notes.
In android, I use Termux
and git
to sync my notes. I have set up my git credentials in Termux
and cloned the repository. I cloned the repository in the ~/storage/shared/obsidian/.obsidian-vault
folder. the directory starts with .
so it is hidden in the android file manager and gallery apps.
In my Termux
.zshrc
I have added an alias to run the script:
obsidian-sync() {
bash ~/storage/shared/obsidian/.obsidian-vault/.obsidian/sync.sh
}
There was some hiccup with safe directory in Termux
so I had to use the ~/storage/shared/obsidian/.obsidian-vault
directory. So, I ran:
git config --global --add safe.directory /storage/shared/obsidian/.obsidian-vault
Now I can run obsidian-sync
from anywhere in Termux
to sync my notes.