[Mobile] Sync with git on iOS for free using iSH

There’s already a post about syncing with WorkingCopy ([Mobile] Setting up iOS git-based syncing with mobile app (using Working Copy)). However, the ability to push is paid, and it costs a lot, but without this there can be no sync!

I propose to use iSH to sync Obsidian with git.

Pros:

  • It’s free!
  • It lets you use fully-featured git - the same git that runs on Alpine Linux

Cons:

  • It requires using the Linux command-line
  • There appears to be a bug in Obsidian 1.0.3 that doesn’t show new files in the file explorer after you pull them from GitHub. This can be easily circumvented by sorting the notes

Tutorial

Also see the example repository I created to showcase this method.

Also see “Simpler way” below.

Assuming you have an existing repo on GitHub. You can also create the repo right from iSH - the git command you’ll be using is the exact same fully-featured git from Alpine Linux.

  1. Create a new empty local vault in Obsidian
  2. In iSH:
    1. First-time setup - install git:
      1. Update Alpine repos: apk update
      2. Install git: apk add git
    2. Create a directory called obsidian in your home directory by running cd ~ && mkdir obsidian.
    3. Mount your local vault folder into the obsidian folder
      1. Run mount -t ios . obsidian
      2. A file picker will show up
      3. Choose the folder with your local vault
    4. Clone your git repository into obsidian
      1. Change directory to obsidian: cd obsidian
      2. Delete the .obsidian folder: rm -rf .obsidian
      3. git clone https://github.com/ForceBru/ObsidianVaultTest . - use your own repository instead. Don’t forget the period . - this is what allows you to clone the repo into the current folder.
      4. (Optional) Run ls -a to see whether your files are there
    5. In Obsidian
      1. Restart Obsidian (might not be necessary)
      2. Open the file explorer
        1. Currently (Obsidian 1.0.3) it’s empty (looks like a bug)
        2. Tap the “Sort” button (the rightmost one, with up/down arrows)
        3. Select any sorting order you like
        4. The files should appear
      3. Use your Obsidian vault!
  3. To push your changes, go back to iSH
    1. Change directory to obsidian in your home directory: cd ~/obsidian
    2. Run git status to confirm that there are modified files
    3. First-time setup - tell git who you are:
      1. Set username: git config user.name ForceBruMobile
      2. Set e-mail address: git config user.email "[email protected]"
    4. Add files, commit and push. For example:
      1. Add all files into the commit: git add .
      2. Commit: git commit -m "Commit from mobile"
      3. Push: git push
        1. This will ask you to enter your username and password
        2. Git can use your personal access token to login automatically
      4. That’s it! Take a look at this example commit from iSH
  4. To pull changes from GitHub:
    1. In iSH:
      1. Change directory to obsidian in your home directory: cd ~/obsidian
      2. (Optional) Check whether there is stuff to pull
        1. Bring remote refs up to date: git remote update
        2. Check status: git status
          1. It should say something like Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded if there is something to be updated
      3. Actually update from the remote repo: git pull
    2. In Obsidian:
      1. Go to file explorer
      2. If you don’t see your new notes, do the sort trick again:
        1. Tap the “Sort” button (the rightmost one, with up/down arrows)
        2. Select any sorting order you like
        3. The files should appear
      3. Updates to existing notes seem to be reflected correctly

Simpler way

Mount the entire Obsidian folder which contains all your vaults (as opposed to mounting just the vault).

In iSH:

  1. Make directory to store Obsidian vaults: cd ~ && mkdir obsidian
  2. Mount the file provider: mount -t iOS . obsidian
  3. Choose On My iDevice and select and open the Obsidian folder
  4. Change directory to obsidian: cd obsidian
  5. Clone the repo with your vault right there: git clone https://github.com/ForceBru/ObsidianVaultTest
  6. This will create a folder called ObsidianVaultTest that will be a git repo and that Obsidian will recognize as a vault

Then open the vault in Obsidian (might need to restart it), edit stuff, then push/pull changes as described in steps 3 and 4 in the original post.

To avoid entering login/password all the time, cache or store your credentials: Git - Credential Storage

3 Likes

Requires a manual push pull?
and is it stored in iCloud or Obsidian app folder?

Yes, pushing and pulling is manual via the command line. The data are stored on your device, but it might be possible to mount the iCloud folder in the same way.

Could there be something done using Shortcuts? Like to run that command from a widget itself?

1 Like

This is great! Though the git add . command is running very slow for me for some reason :thinking:

I imagine it is easy to add some simple push and pull scripts to save time.

~/push

#!/bin/sh
cd ~/obsidian
git add .
git commit -m "Commit from mobile"
git push

~/pull

#!/bin/sh
cd ~/obsidian
git pull

iSH emulates an Intel x86 CPU, so yeah, it can be pretty slow sometimes. It’s indeed possible to add your own scripts - iSH runs real-world Alpine Linux, so it can do basically whatever Alpine can do, except for things restricted by iOS, like USB/Lightning connections.

I’m using iOS 12.4, so I’m guessing it can’t do much in the Shortcuts department. Not sure about what’s possible in more recent versions of iOS.

The cd Command should include the vault name too right? Since obsidian will not have any git. At least it throws an error for me. git add . is way too slow for me as well. :frowning:

How can I run the script? I am getting permission denied.

Okay.
Sadly, it worked for a dummy vault, but as I introduced by own vault, it took ages to execute git add . and simply gets stuck despite keeping the app open forever. I haven’t synced .obsidian folder, only edited one test line in a single MD file. And still I am not able to commit😕

An alternative worth playing with might be a-Shell, ‎a-Shell on the App Store

It’s not as full featured as a shell, but it’s got more native bells and whistles including Shortcuts support.

The command to play with is lg2. It’s a work in progress, but it’s usable and a lot faster than iSH

1 Like

Also, I got into thinking. If working copy free version can sync a folder into obsidian folder and pull and commit, why not use it for everything except push(paid).
Then simply mount the working copy folder in ish or anything and git push!

Because, the add command etc are a lot slower in iSH.

Edit: It works!!
Everything is managed in WorkingCopy. iSH is utilised only for git push
Maybe a super noob manoeuvre. :sweat_smile:

2 Likes

That’s pretty cool, actually: WorkingCopy has great GUI, but pushing is paid, while iSH lets you push for free!

Yes. That’s exactly what I am exploiting for now. :grin:
Even had shortcuts. Pulls when I start obsidian, and commits when I exit obsidian.

Later when I leave ipad, I open ISH and git push. :crossed_fingers: