Skip to content

For Android users

Charles Chiu edited this page Dec 27, 2023 · 12 revisions

Initial steps to install git and link it with logseq

⚠️NOTE: Termux storage space is usually different from the storage space in most "File Explorer App".

  • FX File Explorer(recommended): a file explorer app that allows you to connect to Termux space.
    • Connect to storage > Select "Termux" as storage provider > Select Termux $HOME directory. (no root needed)
    • NOTE: Android's storage space is usually Termux/hOME/storage.
      • ie, the Download folder you normally see in most "File Explorer App" equals to Termux home/storage/downloads

  1. Install Termux in Android, using the F-droid app. Follow instructions here.

  2. Open Termux and type apt update && apt upgrade.

  3. Type pkg install openssh to install SSH for ssh-keys.

  4. Type pkg install git to install Git.

  5. Configure Git username and email:

    git config --global user.name "John Doe"
    git config --global user.email [email protected]

    NOTE: This is the name and email which will go into commits, it can be anything, not necessary related to your GitHub account.

  6. In the Termux terminal, type termux-setup-storage to allow Termux access to your internal storage and/or SD card

  7. In the Termux terminal, create a folder for your graph, for example cd documents; mkdir MyGraph and clone your repo there with the command git clone [email protected]:{your-username}/{your-reponame}.git ~/storage/shared/MyGraph

  8. Open Logseq and add a graph on that folder. Check that all looks ok.

  9. Type git config --global --add safe.directory ~/storage/shared/MyGraph to enable Git operations on that folder.

    NOTE: If you encounter issues like this, please make sure you are using the correct path.

AutoSync via CronJob

NOTE: It might increase your battery usage drastically, I highly recommend the shortcut method below in order to save battery life.

Check this gist for more.

Install shortcuts to synchronize the repository

  1. Install Termux:Widgets from F-droid.

  2. In Termux, type cd ~/.shortcuts and edit a file named, for example, pull-graph containing:

    #!/usr/bin/bash
    eval $(ssh-agent)
    source ~/../usr/bin/source-ssh-agent # path might varied based on your system and brand
    cd {your repo location}  # eg: cd ~/documents/MyGraph
    git pull

    NOTE: If you use password-free private keys for Git you don't need the ssh-agent line. You can include it to avoid typing the private key passphrase each time.

  3. In the same ~/.shortcuts folder create a second one named, for example, push-graph containing:

    #!/usr/bin/bash
    eval $(ssh-agent)
    source ~/../usr/bin/source-ssh-agent # path might varied based on your system and brand
    cd {your repo location}
    git add -A
    git commit -m "sync from android"
    git push
  4. Add a widget for Termux Widget app to the Android screen, which will show the scripts available in ~/.shortcuts (in our example, it will show pull-graph and push-graph). Taping on them, they will be executed by Termux.

Android-Termux-Workflow

  • Tap pull-graph to download the most recent version of your graph from GitHub.
  • Open Logseq and admire the latest version of your notes.
  • Edit/add notes, work on them.
  • Exit Logseq and tap push-graph to upload your changes to GitHub.