Android Git(Hub) setup

What’s your config (tools etc) for developing a Git repo on Android?

Here’s mine. With it I’ve contributed a translation PR to an app and am able to play with a toy GitHub repo. Apps are available from F-Droid unless marked.

Without setup for Git cloning, you can only make single-file commits to the default branch (main/master) via GitHub web interface. The branch restriction is especially bothering because PRs conventionally use dedicated (non-default) branches.

Termux

  • Run termux-setup-storage and grant permission to storage

  • pkg install git

  • ~/.gitconfig:

    [core]
     pager = 
    [user]
     email = ID+USERNAME@users.noreply.github.com
     name = NAME
    [http]
     postBuffer = 1073741824
    [push]
     autoSetupRemote = true
    [alias]
     sb = status -sb
     force-push = push --force-with-lease
     #lg = log --oneline
     lg = log --pretty=tformat:'%C(dim)%C(bold)%h%C(auto)%d %s'
     cl = clone --no-single-branch
     lgwithdate = log --pretty=tformat:'%C(dim)%as %C(bold)%h%C(auto)%d %s'
    
    • Disable pager (pager =) as it seems broken otherwise on my device
    • Email and name can be set to GitHub noreply email and username respectively if you’d like to hide your real email/name
    • Skip the [http] postBuffer = 1073741824 if you like; it doesn’t visibly improve cloning/pushing speed for me
    • [push] autoSetupRemote = true will automatically push branches to remote instead of needing -u origin every time
    • Command alias ([alias]) are for convenience, and I will only explain:
      • cl: equivalent to clone but doesn’t enable single-branch mode when using --depth. There is no Git setting to disable auto-single-branch when using --depth so this is a workaround.
      • lg and lgwithdate: the former is equivalent to log --oneline but changes the hash’s yellow color to gray and boldens it (personal style choice); the second adds date information in addition to that
  • Optional: set up a “put anything here / temp directory” folder

    • Create a file ~/.gitignore_global containing t and set [core] excludesFile = /data/data/com.termux/files/home/.gitignore_global[1]
    • The folder t will then be ignored in every repo without needing to tweak repos’ .gitignore
  • Recommended commit method: git commit -F -

Ghost Commander

Bookmarks for convenience:

  • content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome/document/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome for easy Termux access. This is equivalent to Termux path ~ and is reachable from SAF[2]. You’ll need to keep Termux open and grant permission.

  • Create and bookmark a dedicated folder in non-Termux storage for putting some things there

After granting Ghost Commander access to Termux storage, I use it as the primary tool for editing files.

GitHub (web UI)

Set up a personal access token because GitHub doesn’t accept password authentication anymore. Store it inside Termux storage (which is private).[3] It wil be asked for when you run git push. I can’t pipe it into Git so I have to copy-paste every time. :frowning:


  1. ~/.gitignore_global can be any other file path but the path in .gitconfig needs to agree. /data/data/com.termux/files/home is equivalent to Termux’s ~ ↩︎

  2. Storage Access Framework ↩︎

  3. Let me know if you think it’s not secure. ↩︎

1 Like