How to synchronize Obsidian vault using git on iOS
Obsidian is a great Markdown editor with many plugins. I tried Joplin, but their iOS app just doesn’t cut it for me. Anyway, one obstacle when using Obsidian is synchronization. Obsidian offers paid service for $4/mo to synchronize the vault. However, they don’t provide API to access the synchronized data programmatically. The lack of API support is a deal breaker for my use case.
Table of Contents
Adding your vault to Working Copy
Working Copy is an amazing, actively developed, and maintained git client for iOS. It is a paid app, but it is worth it.
Follow these steps to add your Obsidian vault to the Working Copy.
- Clone your Obsidian vault using the Working Copy application.
- Open Files, navigate to the directory where Working Copy stores the repositories and select the repository which holds your Obsidian vault.
- Copy the repository to the directory where Obsidian stores the vaults.
- Open Obsidian to verify that your vault looks like what you expected.
- Remove the repository from the Working Copy application.
- Add a new repository - this time, instead of cloning a new repository, click to link an external repository. Select the Obsidian vault inside the Obsidian folder. The vault should contain a hidden .git directory with data about remotes, so everything should work seamlessly.
You can now open the vault in Obsidian and edit some files. You should see the changes in the Working Copy application. You can now commit the changes and push them to your remote. Lovely!
Shortcuts
To simplify synchronizing your repository with the git remote, I created a simple shortcut that allows you to back up the repository with a single touch. To use the shortcut, install the Actions app that provides additional actions (duh), such as storing global variables and checking if your device is online.
After you download Actions, you can install the shortcut be clicking here. You will be asked for the git repository and a commit message. You can duplicate the shortcut and change the repository name if you have multiple vaults.
But what if you forget to sync the repository? Wouldn’t it be great to have automatic backups? I am glad you ask.
Automatic backups
I created an iOS shortcut that synchronizes the vault automatically upon opening or closing Obsidian. Just like the shortcut above, this one also requires both Working Copy and Actions.
You can install the shortcut by clicking on this link. You will be asked for two questions:
1. Enter the repository name/pattern to synchronize
This is handy if you have other git repositories that are not Obsidian vaults. I
have quite a few, so I add a ; syncthis
to the names of repositories I want to
synchronize.
2. What is the interval between synchronization?
I often switch back and forth between Obsidian and other applications (music player, web browser, etc.). I don’t think I need the vault to be synchronized every time I do this. By default, the vault will not be synchronized more than once every five minutes. You can set this number to zero to synchronize every time you open or close Obsidian.
3. Enter the commit message
Self-explanatory.
Setting up the automation
The shortcut is now installed, and it is time to set up automation. Open the Automation tab in the Shortcuts app and add a new automation. Configure it such that:
- the type is application
- it fires on both opening and closing of the application
- it fires without approval
- it launches the shortcut you’ve just installed
There is a notification after every synchronization, so you know the last time it happened and can trigger it manually yourself.
Synchronization on desktop
For synchronization on the desktop, install the Obsidian Git plugin, which supports periodic automatic backups, or use git directly.
Happy writing!