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.
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 Tasker from the Play Store.
-
Install F-Droid.
-
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.
-
Run
termux-setup-storage
and give access to files. -
Run
pkg update && pkg upgrade -y && pkg install -y git openssh termux-api
to install packages. Press Enter any time it pauses with a question. -
Run
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 '*'.
-
Run the setup script:
cp "/storage/emulated/0/repos/obsidian-android-sync/setup" ~/ && chmod +x "$HOME/setup" && source "$HOME/setup"
. Typeyes
and hit Enter if prompted. -
The above command copied an SSH public key to your clipboard (or was displayed to the screen), paste this into your Git host's SSH key authentication setting (eg Github). If you want to copy the SSH key again, run the setup script again by simply running
setup
. The long verison of the setup command (above) is not needed anymore. -
In Termux, you should now be in the Obsidian directory (verify with
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. -
Run the following command to apply a fix for Git corruption issues:
"${HOME}/worktree-fix.sh
At this point, you can run sync
to sync all the vaults in the /storage/emulated/0/repos/Obsidian
folder. There will be no output if successful.
- Enable the Termux permission in the settings for the Tasker app.
- Open the Obsidian app and add your vaults from the
repos/Obsidian
folder. - If you're using the Obsidian Git plugin, you should disable it for this device. You can do this in the plugin settings.
- Import the "Tasker project" into Tasker. You can import the project in 2 ways. You can use this TaskerNet link, or you can import (image) the .xml file from this repository. Once it's imported, there will be some prompts, I think one for giving Tasker "Usage Access" and one to enable all profiles. Accept all.
- Give Termux the "Display over other apps" permission.
- Add the Vault launch icons as Tasker widgets (use the widget type that allows you to add them to folders) to the home screen. Also, add the 3 helper tasks as widgets (as needed):
- Sync Vaults - syncs all vaults (now without output see
- Vaults Status - outputs the
git fetch && git status
of each vault - Sync Log - outputs the sync log
All vaults will sync at 4am every day using a Tasker profile.
- You should get a notification if a sync fails. This requires AutoNotification from the PlayStore. To disable this, disable the Sync Error Notification profile. (not working currently)
- If this repository has new commits that you want, running the
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.