# Git / GitHub as the vault sync owner Use when the user wants to move an Obsidian vault off a cloud-folder sync (Drive, rclone, Dropbox) onto Git. ## Decide before configuring Git is a version-history tool used as sync, not a sync engine. Recommend it when the user wants a time machine over their notes; recommend a real sync tool when what they want is "my notes on my phone". Say which one you are optimising for before touching anything. Size the vault first — a markdown-only vault of a few MB has no Git performance problem, and saying so with a real number settles the question faster than a caveat: ```bash du -sh "$VAULT"; du -sh "$VAULT"/* | sort -rh | head find "$VAULT" -type f ! -name '*.md' -not -path '*/.obsidian/*' | wc -l ``` The number that actually decides mobile viability is repo + full history versus free phone RAM, and attachments are the accelerant: images never diff, so every pasted version lives in history forever. Keep binaries in cloud storage and let Git carry the text. ## Split the roles instead of replacing one with the other A problematic cloud drive does not have to be removed; give it the job Git is bad at. - Git/GitHub — markdown notes, history, "what did I delete in March". - Cloud drive — large images, video, PDFs, archive snapshots that would bloat history permanently. Run the old transport alongside the new one until the Git path is verified end to end on every device. Tearing down the working owner first leaves no fallback. ## On desktop, offer the Obsidian Git plugin by default The anti-plugin warning below is about MOBILE only. On macOS/Windows/Linux the plugin shells out to the real `git` binary and behaves exactly like git, so it is the right way to give the user a commit/push button inside Obsidian. Offer it proactively instead of presenting terminal-only as the safe choice — someone who writes notes in Obsidian wants to send them from Obsidian, and turning automation off is a settings decision, not a reason to skip installing it. Preferred install: let the user install it through Obsidian's own community-plugin browser (Settings → Community plugins), which fetches the reviewed release. Only if that is not possible, and with the user's approval, install a pinned release manually: ```bash D="$VAULT/.obsidian/plugins/obsidian-git"; mkdir -p "$D" TAG= # an exact release tag, never "latest" BASE=https://github.com/Vinzent03/obsidian-git/releases/download/$TAG for f in main.js manifest.json styles.css; do curl -fsSL -o "$D/$f" "$BASE/$f"; done shasum -a 256 "$D/main.js" # compare with the checksum/attestation published for that release gh attestation verify "$D/main.js" --repo Vinzent03/obsidian-git 2>/dev/null || echo "no attestation: verify manually" ``` Do not enable the plugin unless the downloaded `main.js` matches a published checksum/attestation for that exact tag (or the user accepts the risk explicitly after being told). Then add the plugin id to `.obsidian/community-plugins.json` — without that file no community plugin is enabled at all. A quick `head -c 60` check only catches an HTML error page from a silent 404; it is not an integrity check. Obsidian picks up a hand-installed plugin only on restart. For manual-only control set every interval to 0 (`autoSaveInterval`, `autoPushInterval`, `autoPullInterval`) with `autoPullOnBoot: false`, but keep `pullBeforePush: true` so a phone's commits cannot be clobbered. Confirm the plugin actually loaded before moving on: it rewrites its own `data.json` on first run (key count grows, an askpass helper appears next to it). That file changing is the proof; a screenshot of the sidebar is not. Keep `.obsidian/` out of the repo ENTIRELY. Selective exclusion is the trap: commit `manifest.json` while ignoring the bundled `main.js` and the second device clones a plugin directory with no code in it and reports a load failure. Per-device settings (`app.json`, `appearance.json`, `workspace*`) collide on clone for the same reason. Each device installs its own plugins; the repo carries notes only. If `.obsidian` was already committed, `git rm -r --cached .obsidian` keeps the working copy while dropping it from tracking. ## On mobile, size decides which client Neither iOS nor Android lets an app run the real `git` binary, so the Obsidian Git plugin substitutes a JavaScript reimplementation (isomorphic-git). That drops SSH (HTTPS + token only), rebase, submodules, and git-lfs, and puts the whole operation inside the app's RAM. The documented failure modes — crash-on-clone, buffer overflow, never-finishing pull — are real but CONDITIONAL: they describe repo-plus-history versus free phone RAM, with the initial clone as the worst moment. The plugin's own docs recommend against mobile use without stating the threshold, so measure instead of inheriting the verdict: ```bash du -sh "$VAULT/.git"; git -C "$VAULT" rev-list --count HEAD; git -C "$VAULT" ls-files | wc -l ``` A few MB of `.git` with a few dozen commits and no binaries is nowhere near the failure regime; recommending a separate app at that size is over-caution that costs the user a working in-app button. Vaults with years of history or pasted images are where the warning bites, and that is when to move Git out of Obsidian: a native mobile Git client (GitSync and similar — real git core, SSH, background sync) clones into a plain folder and Obsidian just opens that folder as a vault. Termux is the same shape with more setup; it earns its keep only when the user already has it and wants scripted control. When the plugin route is viable, two prerequisites make it work and both are checkable from the desktop: ```bash git -C "$VAULT" remote -v # must be https:// — isomorphic-git cannot do SSH grep isDesktopOnly "$VAULT/.obsidian/plugins/obsidian-git/manifest.json" # must be false ``` The plugin clones by itself (`Git: Clone an existing remote repo`), so skip the USB / `adb push` folder-copy step that older guides open with. On the phone: create a vault, enable community plugins, install Git, clone into it. Auth is a GitHub fine-grained token scoped to that one repo with Contents read-write — the user creates and pastes it on the device; never ask for it or accept it in chat. Git sync is timer-based on both ends, so expect minutes of lag and a real merge-conflict risk if a device edits a stale copy; do not present it as live sync. The rule to hand the user is: send from the device you wrote on before switching devices. Verify BOTH directions with real commits before calling the setup done — a successful phone push proves nothing about the pull path. Read the phone's commit from the remote API, then `git pull` it on the desktop and confirm the content landed. Differing committer names between devices are normal and useful for telling which device wrote what. ## Setup order 1. Create the private repo. 2. Write `.gitignore` BEFORE the first commit — `/`, ``, any personal-health or private folder, `.obsidian/workspace*`, `.DS_Store`, `.trash/`. Private visibility is not a substitute for exclusion; history is permanent. 3. Prove the exclusions actually fire before committing: `git check-ignore -v "/x.md" ".obsidian/plugins//data.json"` must name a rule for every sensitive path that exists on disk, and scan the staged diff for token-shaped strings. A `.gitignore` line that fails to match (missing trailing slash, wrong case, Unicode folder name) fails silently and the leak is permanent. Distinguish a real secret from prose that merely names key fields before raising an alarm. 4. Push only with the user's explicit approval. 5. Verify the push from the REMOTE, never from local git: `gh api repos///git/trees/main?recursive=1 --jq '.tree[].path'`, compare its blob count with `git ls-files | wc -l`, and grep it for the excluded folders. A clean local status is not evidence of what landed. 6. Verify on the second device before retiring the previous sync owner. ## Routine commit + push from the desktop (user asks "commit/push the vault") The request itself is the push approval for that batch; everything pending since the last commit goes, so check what that is first. A bare "commit" (or "yes" to a commit offer) is NOT push approval: commit locally, leave `main` ahead of `origin/main`, and say so. The git root is the vault folder itself (``), not its parent ``; run `git rev-parse --show-toplevel` there before anything else. When the last commit is weeks old the batch is far wider than the task that prompted it (hundreds of files across unrelated folders), so after staging report the staged count by top folder and say the message covers more than the task; offer to split by folder pathspec before the user pushes. If asked "what commit is that", answer with repo path, remote, hash, file count, content summary and whether it is pushed. Flag staged config-like files (`.json`, `.hujson` network policies) for a security review before any push. 1. Read `.gitignore` and `git log -1`; `git fetch` and confirm `main...origin/main` is not behind before committing. 2. List pending changes with private folders excluded by pathspec so their names are never printed: `git status --porcelain -uall -- . ':(exclude)'`. Summarise by top folder; flag binaries. 3. Exclude via pathspec ONLY folders that are not already gitignored. An `:(exclude)` pathspec for a gitignored folder makes `git add` print the "paths are ignored" hint and exit 1 after partially staging; ignored folders are already safe. Always re-check `git diff --cached --name-only` for private prefixes (expect 0) and the staged count before committing. 4. Scan only the staged files for token shapes (`sk-`, `ghp_`, `AKIA`, `xox[bp]-`, `AIza`, `BEGIN ... PRIVATE KEY`) printing file names only; inspect a hit with a short masked context. Kebab-case prose (any kebab-case word whose first part ends in `sk`, e.g. Turkish `disk-...` compounds) is a common false positive. 5. Commit with a dated message, `git push origin main`, then verify on the remote ref: `git -c core.quotepath=false ls-tree -r --name-only origin/main | grep ''`. Without `core.quotepath=false` non-ASCII names come back octal-escaped and a grep for a Turkish filename falsely reports 0. 6. If a private folder is not in `.gitignore`, say so and offer to add it: the phone's Obsidian Git auto-commit would push it. Do not open it to check whether it is already tracked. ## Migrating a scheduled script off the old transport A vault usually has an automation (nightly research, backup job) that calls the old sync tool directly, so the transport is not gone until that script changes — stopping the service while the cron still invokes it leaves the old owner alive on a timer. Replace the sync function body rather than the whole script, keep its existing log/notify contract, and exercise BOTH branches before trusting the schedule: with no changes present it must no-op silently, and with a real edit it must commit and push. Confirm the resulting commit from the remote API afterwards. Then grep the script for the old tool's name — a lone hit in a docstring is fine, a hit in a command list is not.