Yet Another Obsidian Git Tutorial (Desktop & iPad Sync)
Originally posted on Gist
But why?
Well, I haven’t seen a single tutorial that covers all the steps I took to achieve a working sync solution. There are immensely helpful ones out there, but I still need to hack some of the bits to make it work for me.
As a Git noob, trying to find the said “hacks” from multiple sites and pages was extremely frustrating. I don’t trust my fuzzy brain to remember all that either, so I must take note of everything. So, take note I did with this tutorial.
My devices are as follows:
- Desktop: Toshiba Laptop running Bunsenlabs (Debian)
- Mobile: iPad 8th Generation
(As a disclaimer, I have no idea on how to write a tutorial properly. Expect a mess, I apologize in advance.)
Setting Up Git On Desktop
Apps I used:
- Git (see installation docs such as this for more info)
- Github Desktop (I installed mine from Flathub… Windows and Mac users can check out the download instructions here instead)
- Text Editor
- Obsidian desktop app with Obsidian Git plugin installed
Getting Started - Initial Steps
To get started, I follow the instructions— specifically sections one (Install backup requirements), two (Create Repository), and three (Obsidian Git Setup)— on Danny Hatcher’s beginner tutorial.
I also add a .gitignore text file on my vault folder (not in .git folder) that contains the line .obsidian/
.
You can stop at that if you’re fine pushing and pulling changes via Github Desktop app. Obviously, I’m not (fine), so I decided to configure Git SSH. I chose this method because the default HTTPS option doesn’t work on my end.
Configuring Git SSH - All That Remains
Here’s what I did to configure Git SSH. First, I follow the instructions on Github Docs about generating a new SSH key and adding it to ssh-agent (saw the link on one of Steve Griffith’s (aka Prof3ssor St3ve) videos):
Instructions on generating a new SSH key:
- Open the terminal and type
ssh-keygen -t ed25519 -C "github_email"
, where"github_email"
is the email you use on your Github repository. - If it was successfully generated, you should see this message:
Generating public/private ALGORITHM key pair.
- Then, there would be a prompt along these lines:
Enter a file in which to save the key (/home/jan/.ssh/ed_25519)
, where/home/jan
is my/home/user
directory and/ed_25519
is the algorithm name. I leave it at default, so I simply hit the Enter button to continue. - Another prompt will appear:
Enter passphrase (empty for no passphrase):
, where passphrase is the “password” for your SSH key. Type it out, and hit Enter. - Type the passphrase again when the prompt
Enter same passphrase again: [Type passphrase again]
appears, then hit Enter. - See the confirmation with matching fingerprint graphics on the terminal? If yes, then congrats, you just generated a SSH key!
Now, onto adding the key to ssh-agent:
- Open the terminal and switch to root. In my case, I ran
sudo -s -H
. - Start the ssh-agent in the background by typing
eval "$(ssh-agent -s)"
- Finally, add the key to ssh-agent by typing
ssh-add /home/jan/.ssh/id_ed25519
, where/home/jan
is my/home/user
directory.
Next, I added the keys on my Github account using the instructions here:
- To see the key, I typed
cat /home/jan/.ssh/id_ed25519.pub
on the terminal, where (for the nth time)/home/jan
is myhome/user
directory (Note: If you save your key elsewhere, change the directory accordingly). Hit enter, and copy the key. - On Github website, log in your account, click your profile photo, then click “settings”.
- On the settings page, click “SSH and GPG keys” (look at the left sidebar).
- Click “Add SSH key” (or “New SSH key” if you already have existing keys).
- For the “Title” field, adding a descriptive label is recommended. In my case, I typed
Toshiba Laptop (Bunsenlabs)
. - In the “Key” field, paste the key you copied from the terminal.
- Click “Add SSH key” to confirm changes.
- For the “Title” field, adding a descriptive label is recommended. In my case, I typed
Another set of instructions down, one more to go.
So, the last step is to set your .gitconfig in your vault to use SSH:
- On Github website, access your repository page. You know you’re right there when the URL is
https://github.com/github_username/repository_name
. - Click “<> Code” button and under Local>Clone, switch from HTTPS to SSH. Copy the link that looks like this:
[email protected]:github_username/repository_name
- Open your Obsidian Vault folder, then the .git folder (tick “show hidden files” in your file explorer if needed).
- Open the “config” file inside the .git folder with a text editor.
- Under [remote “origin”], change the default HTTPS URL to the SSH one you copied on step 2 and hit save.
With this, you can push and pull changes on your desktop within the Obsidian app using the Obsidian Git plugin. Just type your SSH key passphrase when prompted.
Setting Up Git On iPad
Apps I used:
- iSH Shell (a free Linux-like shell on iOS)
- Obsidian mobile app (no need to install Obsidian Git plugin)
Preparing iSH
Before you can use iSH properly for syncing your Obsidian vault, you must install Git and busybox (DOAS) first. Type the following commands:
apk update
apk upgrade
apk add git
for Git, thenapk add doas
for Busybox
That’s it. Onto the next!
Using iSH To Connect Obsidian Mobile To Desktop’s Git Repository
The following steps are based from a Gist tutorial made by Professor Danny Quah. So many Danny’s, ha!
But before proceeding, get a personal access token first since you’ll need it in the git remote add origin
step later.
Here’s how to get the said tokens, courtesy of this forum post:
- On Github website, log in, click your profile photo, and then click “Settings”.
- On the “Settings” page, click “Developer Settings” (look at the left sidebar).
- Select “Tokens (Classic)” under “Personal Access Tokens” section.
- Select “Generate New Token”, then “Generate New Token (Classic)”. Confirm access by typing your Github account password if needed.
- In the “Note” field, you can input whatever name you want for your token. In my case, I simply typed
For Obsidian Git
. I also set my expiration date to no expiration. Then, under the “Select scopes” section, I checked “repo”. - Click “Generate Token” button. On the next page, copy the token before leaving or else, you would need to regenerate it again. Oh, and also, do NOT share it.
- Paste your token on the part I labeled as
personal_access_token
:https://[email protected]/your_username/repository_name.git
.
There you go. Save this for later (for step 6 below). It should look something like this: https://[email protected]/workingja/repository_name.git
Now, do this:
- Open Obsidian Mobile app and create a new local vault (don’t turn on the “Store in iCloud” option). For simplicity, I name it as the title of my Github repository. Close the app after.
- Open iSH and make a mountpoint by typing
mkdir /mnt/your_username/Obsidian
, where including/your_username
is optional. I used it, anyway. Danny Quah used “dq” while I used “workingja” as inmkdir /mnt/workingja/Obsidian
. - Assuming you include
/your_username
too, mount the directory by typingmount -t ios null /mnt/your_username/Obsidian
. In the file picker, navigate to the main Obsidian folder (not the specific vault folder) and select it. - Change directory to the vault you created in step 1 by typing
cd /mnt/your_username/Obsidian/vault_name
. Hit enter. - Initialize Git by typing
git init
. - Add the Git remote by typing
git remote add origin https://[email protected]/your_username/repository_name.git
. - Assuming you didn’t rename your Github branches, type
git branch -M main
. Hit enter. - Do
git pull --rebase origin main
, hit enter, and wait for it to finish downloading your files. - Finally, type
git push -u origin main
, and then hit enter.
You’re done setting up your desktop, mobile, and Github repository for syncing. But of course, it won’t automatically sync like Google Docs. It’s Git, alright! The section below details how to do it (manually).
Workflow To Actually Sync Your Obsidian Vault Across Devices
The steps below are lifted once again from Professor Danny Quah’s tutorial. Credits to him!
Using Obsidian on Mobile:
- Open iSH. I personally don’t unmount, so I don’t need to type the mount command again. But if you do, type
mount -t ios null /mnt/your_username/Obsidian
and hit enter. - Change directory to your vault using the command used earlier (
cd /mnt/your_username/Obsidian/vault_name
). Then, pull changes withgit pull
. - Work away and use Obsidian mobile app. Once you’re done, change directory to your vault again (it resets whenever you close the iSH app, use the same cd command as step 2) and commit-push changes by typing
git add .; git commit -m "Message"; git push
.
Using Obsidian on Desktop:
- In Obsidian desktop app, open the command palette and select “Obsidian Git: Pull”. You can also do it via Source Control sidebar tab which you can open via command palette>“Obsidian Git: Open source control view”.
- Work away and use Obsidian desktop app. Once you’re done, commit-push changes by selecting the following on the command palette: “Obsidian Git: Create backup” OR “Obsidian Git: Commit all changes”, then “Obsidian Git: Push”. Alternatively, you can use the Source Control sidebar tab just like in step one.
Credits
Big thanks to:
Without their videos and write-ups, this tutorial of mine wouldn’t be possible.
Created by Jan (workingja), 2023-09-17