Skip to content

Instantly share code, notes, and snippets.

@pourmand1376
Forked from Makeshift/tutorial.md
Created November 9, 2022 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pourmand1376/c2e88ebab466e06784254e71c9575737 to your computer and use it in GitHub Desktop.
Save pourmand1376/c2e88ebab466e06784254e71c9575737 to your computer and use it in GitHub Desktop.
Tutorial for automatically syncing an Obsidian vault with Git on an Android device

How to sync Obsidian with Git on Android

Limitations

  • If Termux is closed in the background by Android, the cron service will stop updating your repository and you must open Termux again. Refer to instructions for your device model to disable the killing of certain background applications.
  • This may negatively affect your devices battery life. I'm not entirely sure yet.

Setup

  • Install Termux – Apps on Google Play
  • Open Termux, run termux-change-repo. Press the ↓ button and press spacebar to tick all repositories, then press enter to move to the next screen
  • Press ↓, then spacebar to tick the "Mirrors hosted by Albatross", press enter
  • Run pkg install git -y
  • Run termux-setup-storage
  • Run cd storage/shared (If you get permissions issues, refer to this page)
  • Run git config --global credential.helper store
  • Run git config --global user.email "<your_email>"
  • Run git config --global user.name "<The name you want on your commits>"
  • Run git config --global pull.rebase true
  • Run git clone <your repository> and enter your login when prompted. You may need to create a personal access token if you're using GitHub.
  • Install and open Obsidian
  • Click "Open folder as vault", click on your phone name at the top to navigate to the top directory, and click on your git repository name. Then click "use this folder"
  • With this setup so far, you will need to manually go into the folder in Termux and type git pull. If you'd like to create shortcuts to do this on your homescreen, see this guide

To enable auto-syncing

  • Run pkg install cronie termux-services
  • Restart Termux by typing exit.
  • Run sv-enable crond
  • Run crontab -e and enter */30 * * * * ~/sync_repo.sh (This syncs every 30 minutes)
  • Click the CTRL button, and type x. Type y and enter.
  • Type nano sync_repo.sh and enter:
#!/bin/bash
cd ~/storage/shared/<your repository name>
git add .
git commit -m "Android Sync $(date)"
git pull
git push

(This is a very basic sync and will not handle things like merge conflicts)

  • Click the CTRL button, and type x. Type y and enter.
  • Run chmod +x sync_repo.sh
  • Test your script by running it like so ./sync_repo.sh

Assuming Android doesn't kill the background service, it will now sync Obsidian automatically.

@pourmand1376
Copy link
Author

pourmand1376 commented Nov 9, 2022

git add .
git commit -m "Android Sync $(date)"
git pull
git add .
git commit -m "automerge in Android"
git push

@pourmand1376
Copy link
Author

pourmand1376 commented Nov 9, 2022

For ignoring commit mesage when merge:

git config --global core.mergeoptions --no-edit

Not working!

@szareui
Copy link

szareui commented Dec 14, 2022

To install openssh:

apt update 
apt upgrade
pkg install openssh

@pourmand1376
Copy link
Author

For ignoring commit mesage when merge:

git config --global core.mergeoptions --no-edit

This one didn't work. So I understood that I shouldn't use git pull. Instead I should use:

git fetch
git merge --no-edit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment