Post

Encrypt & sync using git for Obsidian and Logseq

If you want to encrypt your files (Obsidian/Logseq) before pushing to a git-host and sync with your Android Device, this is your post

Encrypt & sync using git for Obsidian and Logseq

Hi again,

I have a post about how to take a back up from Obsidian and Logseq. But I found there are two problems: first is that our files is not encrypted on Github or Gitlab servers, second, is that after the Internet outage in Iran, I decided to take a back up on a local Git-server (by a company running Gitlab on its servers), but as far as I don’t trust this company and Iranian government at all, I decided to increase my father before pushing to the repository.

So, I got familiar with git-crypt and I tried to setup.

After searching I found this Repository which is great.

Obsidian notes with git-crypt guide (including android scripts and utilities)

ℹ Same method goes for both Obsidian and Logseq

How to setup using git-crypt

If you had setup git before, just initiate git-crypt: using git-crypt init

DO NOT forget to export decryption key (I prefer to export it to .config directory):

1
git-crypt export-key ~/.config/git-crypt-logseq

Configuration of .gitignore and .gitattributes

Now its time for configuring .gitignore. These are my preferences:

For Obsidian:

1
2
3
4
5
6
.obsidian/workspace
.obsidian/cache
.obsidian/icons
.smart-connections
.DS_Store
.stfolder

For Logseq:

1
2
3
4
5
logseq/bak/
logseq/.recycle
.DS_Store
.stfolder
.stignore

Now its time for the most important part:

Configuring .gitattributes The encryption guide for git-crypt

Logseq:

1
2
3
4
5
*.md filter=git-crypt diff=git-crypt
*/** filter=git-crypt diff=git-crypt
logseq/** !filter !diff
.gitattributes !filter !diff
README.md !filter !diff

Obsidian:

1
2
3
4
5
6
7
8
9
*.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-crypt
.obsidian/** !filter !diff
.gitattributes !filter !diff
.makemd/** !filter !diff
README.md !filter !diff

I’ve excluded .obsidian and some other files and folders using !filter because I believe encrypting my settings and plugins is not meaningful

You can remove .obsidian/** !filter !diff to make it encrypt this folder (plugins and settings)

⚠ Test your .gitattributes file using this command:

git ls-files -z |xargs -0 git check-attr filter |grep unspecified

Final steps

Same as explained here

If 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): quote

1
2
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/config to be updated with this… [quote]

1
2
3
[oh-my-zsh]
hide-status = 1
hide-dirty = 1

test encryption:

1
git-crypt status -e

Unlock the Vault:

1
git-crypt unlock ../git-crypt-key

Solving Mac problem

read this section

Android sync

Follow the instruction from this section

Notes

In these three files pull.sh, push.sh, log.sh :

  1. Specify path clearly: I faced an error related to repo.conf so I changed it!
1
2
source ~/.shortcuts/repo.conf
cd ~/storage/shared/$GH_REPO

Note: you can remove repo.conf and place the path directly in these files

Exclude some file in Android synchronization:

I prefer to exclude some files from Android, so edit .git/info/exclude in proper directory (obsidian or logseq). This is for my obsidian:

1
2
3
4
5
6
7
.obsidian/
.obsidian/*
Aapps/*
Sets/*
Spaces/*
.makemd/*
.stignore

Copy of content

All credits goes to original auther:

A copy is available at my account: alerezaaa/obsidian-scripts

Common Issues

  • if you get errors on git push and it gets stuck on 100% but not finishing, considering increasing your httpBuffer in 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)
1
git config --global http.postBuffer 524288000

Obsidian Git plugin (desktop)

If 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):

1
2
3
4
5
6
[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\\" diff

If 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 gpg installed
1
2
type gpg
gpg is /usr/local/bin/gpg
  • then configure git to use that full path
1
git config --global gpg.program /usr/local/bin/gpg
  • FYI - this results in your global .gitconfig to be updated with this…
1
2
[gpg]
program = /usr/local/bin/gpg
This post is licensed under CC BY 4.0 by the author.