Easily sync your Obsidian vaults on Android using Git (SSH) + Termux, with automation and shortcuts using Tasker. It works by syncing a vault when it's opened and when it's closed.
Here's an image of what it looks like, once complete with shortcuts to some optional utility functions. Each vault will have it's own icon. This allows syncing to be more efficient as without it, all vaults will sync each time in a specific order. Instead of just the vault that you open being synced immediately. If you only use one vault or don't mind the inefficiency of waiting for the vault that you just opened to be updated, then you can use the default Obsidian app icon. Also, all vaults are synced once a day (defaults to 4am).
To prevent conflicts, I recommend you add the following lines to your .gitignore file in all your vaults that you'll be syncing using Git. If you notice a plugin has a file which is often in conflict, you'll want to add that as well (remember to un-track it with git rm --cached <file>
):
/.obsidian/workspace.json
/.obsidian/workspace-mobile.json
/.obsidian/plugins/obsidian-git/data.json
/conflict-files-obsidian-git.md
To stop conflicts from happening with your note files, you can create a .gitattributes file in the root of your vaults with the following content. It will basically always accept both changes for .md
files.
*.md merge=union
Install Termux, Termux:Tasker, and Termux:API apps from F-Droid (NOT from the Play Store).
The next steps will mostly ask you to run commands in Termux.
termux-setup-storage
and give access to files.pkg update && pkg upgrade -y && pkg install -y git openssh termux-api
to install packages. Press Enter any time it pauses with a question.mkdir -p /storage/emulated/0/repos/Obsidian
to create the directories used for repositories.Run git clone https://github.com/DovieW/obsidian-android-sync.git ~/storage/shared/repos/obsidian-android-sync
to clone this repo into the repos directory.
Be aware that the next step will set safe.directory to '*'.
cp "/storage/emulated/0/repos/obsidian-android-sync/setup" ~/ && chmod +x "$HOME/setup" && source "$HOME/setup"
. Type yes
and hit Enter if prompted.setup
. The long verison of the setup command (above) is not needed anymore.pwd
) where you should now clone your Obsidian vaults. Try not to put any special characters (that are recognized by bash) in your vault name (eg an ampersand or exclamation point etc), if I remember correctly, it gave Tasker some issues, but you can probably get around that issue if you try. I don't know how spaces will behave.At this point, you can run sync
to sync all the vaults in the /storage/emulated/0/repos/Obsidian
folder.
repos/Obsidian
folder.git fetch && git status
of each vaultAll vaults will sync at 4am every day using a Tasker profile.
setup
command should pull them down. After which, you may be prompted to run a command to update the setup script itself, if it was updated.