How to Use Obsidian Git Sync on Android¶
On this post, I'll show how to sync your obsidian vault on obsidian start-up using tasker on your android phone.
Inspirations¶
- My old guide using cron jobs with time intervals instead of tasker
- How to sync your obsidian vault on mobile using git
- Mobile Sync for Obsidian | Some Thoughts
- Automatically sync notes to and from git repository whenever you open and close Obsidian on mobile. · GitHub
- Obsidian Syncing Alternative (For Android and iOS) | Obsidian-Sync-Alternative
Install the Required Tools¶
Install Tasker from the official website (7 days trial) or from the Google Play Store (~3.5€).
Install Termux, Termux Widget, Termux Tasker on F-droid or on the official Termux Github repository.
Never use the play store version
Trust me it is depreciated.
Give Termux access to your storage using the following command :
Setup Git and Github for Manipulating Repositories¶
Use the following commands to setup git and github via HTTPS :
You can use SSH or an access token as well instead of using gh
Login to your Github account :
Update the git configs :
Go into the shared folder :
Clone your repo :
Try using the following commands :
Android 12 warning
If you are on Android 12, you'll get an error with the command required to add the repository to a security list or something like that. Do it, and these commands should work.
Change the Default Termux Working Directory¶
Edit the bashrc file :
And append this line to the end of the file :
Restart your terminal, and you will find that it always opens up in your desired directory!
Setup Tasker¶
Launch Tasker and do the basic setup (setting battery optimisation and stuff).
Give Tasker some important Termux permissions
Android Settings -> Apps -> Tasker -> Permissions ->Additional permissions -> Run commands in Termux environment.
- Launch Termux
mkdir ~/.termux/tasker/
cd ~/.termux/tasker/
- nano pull.sh
- Add the following script :
- nano backup.sh
- Add the following script :
#!/bin/bash
git add -A
git commit -a -m "android vault backup: `date +'%Y-%m-%d %H-%M-%S'`"
git push
exit 0
Don't forget to edit permissions to termux home folder :
chmod 700 -R /data/data/com.termux/files/home/.termux
Create an Obsidian profile :
Setup the following task :
Setup the Error Handling Shortcut for Merge Conflict¶
Create a directory for the shortcuts :
mkdir -p /data/data/com.termux/files/home/.shortcuts
chmod 700 -R /data/data/com.termux/files/home/.shortcuts
Create the sync script :
Add the following script :
Create the widget and add it to your home screen. That's it, you just need to launch it to solve merging errors.
Setting up an Automatic Execution of the Script (Not Recommended if You Want to Avoid Merge issues)¶
If you want to automatically sync your vault every hour, for instance, you can do it using a Cron job (like described in this thread or this one).
First, create the auto sync task folders :
mkdir -p /data/data/com.termux/files/home/.shortcuts/tasks
chmod 700 -R /data/data/com.termux/files/home/.shortcuts/tasks
Create the sync script inside .shortcut/tasks
:
#!/bin/bash
cd storage/shared/LifeWiki
git pull && git add -A && git commit -a -m "android vault backup: `date +'%Y-%m-%d %H-%M-%S'`" && git push
Difference between .shortcuts and .shortcuts/tasks folders
What is run inside .shortcuts are just scripts launching Termux. If it is run under the tasks folder, it will launch it as an underground task.
First, you need to install Cron :
Then, you'll restart Termux and then run the following :
Finally, you'll end up with the crontab -e
command in the nano text editor. Add the following :
You just need to keep Termux opened in order for the job to be able to launch.
You can find information about Cron job easily on the internet.
Edit : I already uploaded a guide to do it with a cron job. I kept this part, but I wanted something less energy consuming. Hence I learned how to use Tasker and did it this way. I find it as simple as the obsidian-git plugin on computer, but on mobile ! Hope it helps !