git-crypt(install viabrew install git-crypt)- Obsidian app installed ( download)
- folder created for your Obsidian vault (i.e
~/ObsidianVault)
- initialize git repository (as you normally would)
$ cd YourVaultFolder
# delete existing git repo
# let's not expose cleartext history!
$ rm -fr .git/
$ git init- initialize
git-crypt
$ git-crypt init- copy the generated secret key to
~/git-crypt-key(you will need thisgit-crypt-keyto decrypt your vault on other devices so might wanna back it up 🤙)
git-crypt export-key ../git-crypt-keyHere is sample .gitignore, you may want to put the entire .obsidian directory into there, but I like keep my plugins/extensions/etc as well:
.obsidian/workspace
.obsidian/cache- i'm basically encrypting everything including my plugins
*/**, but this can be fined tuned later as you please (all markdown files, all obsidian canvas files, all other files)
*.md filter=git-crypt diff=git-crypt
*/** filter=git-crypt diff=git-crypt
*.canvas filter=git-crypt diff=git-crypt
BrainPad/** filter=git-crypt diff=git-crypt
BrainPad.md filter=git-crypt diff=git-cryptIf you’re using oh-mz-zsh, the following two commands will prevent it from slowing down your command line (this will modify your vault repo's git config, not the global config):
$ git config --add oh-my-zsh.hide-status 1
$ git config --add oh-my-zsh.hide-dirty 1- FYI - this results in your vault's
.git/configto be updated with this...
[oh-my-zsh]
hide-status = 1
hide-dirty = 1- run this command
git ls-files -z |xargs -0 git check-attr filter |grep unspecified- you should only see non critical files like
.gitattributesbe reported as unspecified - if any file is mentioned here that you want to be encrypted, tweak your
.gitattributesfurther
- you should see all your encrypted files listed in the output (might take a while)
git-crypt status -eTo unlock your Vault's git repo, run this (using ../git-crypt-key backed up earlier):
git-crypt unlock ../git-crypt-key- create private empty repository on GitHub (follow the instructions about how to push an existing repository that come up upon creation)
replace
YourGithubUsername/YourVaultRepowith your own
$ git remote add origin \
git@github.com:YourGithubUsername/YourVaultRepo.git
$ git branch -M master # ...
$ git push -u origin masterNote: From now on, you can add, commit, push from this repository, and
git-cryptwill transparently encrypt and de-crypt your files.
- if you want, you can lock your vault once you are done (don't have to)
git-crypt lock- install the
Obsidian Gitplugin- configure the plugin: Make sure,
Disable pushis deactivated. - do this on all your desktop/laptop machines
- configure the plugin: Make sure,
Now, every time you want to sync your changes, press ctrl+p and search for “Obsidian Git : commit …”
The plugin will automatically pull all remote changes when you start Obsidian.
If you leave it running for days, you might want to pull recent changes manually: ctrl+p and search for “Obsidian Git: Pull”.
- if you get errors on
git pushand it gets stuck on 100% but not finishing, considering increasing yourhttpBufferin your global git config and retry (this may be the first time you are pushing something bigger, if you decided to backup your plugins/extensions etc like me)
git config --global http.postBuffer 524288000If you are seeing git-crypt related errors in Obsidian on your desktop, it is most likely unable to find git-crypt in your path. Instead, tell your .git/config the explicit path to git-crypt executable (modify it manually):
[filter "git-crypt"]
smudge = \"/opt/homebrew/bin/git-crypt\" smudge
clean = \"/opt/homebrew/bin/git-crypt\" clean
required = true
[diff "git-crypt"]
textconv = \"/opt/homebrew/bin/git-crypt\" diffIf you get any gpg errors, add the path of your gpg executable to your global git config as well.
- first check the full path to the
gpginstalled
type gpg
gpg is /usr/local/bin/gpg- then configure git to use that full path
git config --global gpg.program /usr/local/bin/gpg- FYI - this results in your global
.gitconfigto be updated with this...
[gpg]
program = /usr/local/bin/gpg- install latest Termux from F-Droid
- install Termux Widget 0.13+
- upgrade packages
pkg upgrade- install required packages
pkg install git git-crypt- make storage available in Termux (
/storage/shared/*)
termux-setup-storage- generate new SSH key (press enter for empty passphrase)
ssh-keygen -t ed25519 -C "your_email@example.com"- add your new SSH key to your github account (see here)
- clone the vault repository into Termux home (for now)
replace
YourGithubUsername/YourVaultRepowith your own
git clone git@github.com:YourGithubUser/YourVaultRepo.git- copy the
git-crypt-keyfile into termux (you can zip it togit-crypt-key.zipand transfer to your device using your favorite method) - unlock the vault repository (this might take a while)
# go inside
cd YourVaultRepo
# unlock your vault
git-crypt unlock ../git-crypt-key- once unlock is finished, move this github vault repo to the shared folder; this is because Obsidian app needs to be able see it:
# go back home
cd
# move to your storage
mv YourVaultRepo storage/shared/To take this up a notch further, this gives us very handy commit and push and a pull shortcut that we can launch directly from the comfort of our homescreen
Clone the repository, then copy the pull.sh, push.sh, log.sh , repo.conf into your termux .shortcuts directory to be able to trigger them from homescreen widget.
- clone the repo containing
.shscripts and.conffile
git clone git@github.com:snazzybytes/obsidian-scripts.git- copy all files from
androidfolder to Termux's.shortcutsdirectory (needed to get Termux Widget working)
cp obsidian-scripts/android/* .shortcuts/- update
repo.conffile with your github vault repo name (this is used by the push/pull/log.shscripts)
GH_REPO=YourVaultRepo- make sure they are executable
# go inside and change permissions
cd obsidian-scripts
chmod +x pull.sh push.sh log.sh
# go back to home directory
cd- drop Termux:Widget on your homescreen and you should now see the scripts from
.shortcutsshow up on the list
BOOM 🚀🔥! Now you can access your encrypted vault on android too and push encrypted changes to github. see here for demo
per latest Termux Widget version 0.13+ all custom scripts in Termux
.shortcutsdirectory need proper shebangs#!/data/data/com.termux/files/usr/bin/bash
pull.sh (allows to pull remote changes)
#!/data/data/com.termux/files/usr/bin/bash
source repo.conf
cd ~/storage/shared/$GH_REPO
git pull
cd ~
bash -c "read -t 3 -n 1"push.sh (allows to commit and push note changes)
#!/data/data/com.termux/files/usr/bin/bash
source repo.conf
cd ~/storage/shared/$GH_REPO
git add .
git commit -m "android on $(date)"
git push
cd ~
bash -c "read -t 3 -n 1"log.sh (allows you to check which version you are on with git log)
#!/data/data/com.termux/files/usr/bin/bash
source repo.conf
cd /data/data/com.termux/files/home/storage/shared/$GH_REPO
git log
cd ~
bash -c "read -t 5 -n 1"- https://willricketts.com/obsidian-changed-everything-for-me/
- https://github.com/AGWA/git-crypt
- https://buddy.works/guides/git-crypt
- https://medium.com/@dianademco/writing-in-obsidian-a-comprehensive-guide-58a1306ed293
- https://renerocks.ai/blog/obsidian-encrypted-github-android/#checking-it-out-on-a-different-machine
- https://publish.obsidian.md/git-doc/Start+here
- Vinzent03/obsidian-git#21
