Handling merges and conflicts in an encrypted GitHub Zettelkasten

Git-crypt doesn’t do merges out-of-the-box

Installing a merge handler for git-crypt

Obsidian / Computer

I have taken the essentials of this solution from this GitHub issue, which looks promising. So, first, we need to add to .git/config. In preparation for other repositories, we create a file with these contents, name it git-config-for-merge, and place it in the root of our vault:

  • either via Obsidian push
  • or manually:

Other systems

Since we checked in the merge tool, we need to pull in those changes and run the installer:

  • via Obsidian: git pull
  • or via command line: git pull

Android

We repeat what we did for Obsidian on other systems:

How to handle merges

Four kinds of merge situations can come up when pulling remote changes:

  1. Pull fails due to uncommitted changes
  2. Push fails because the GitHub repository is ahead
  3. Standard merge, where git handles everything for you
  4. Merge fails with conflict markers in affected files

Merge situations

Case 1: Pull fails due to uncommitted changes

In Obsidian, on pull, you will get the notification that “pull failed due to uncommitted changes”.

Case 2: Push fails because GitHub repository is ahead

This is the case when you change a file, like your daily note, that previously has been changed on another device and when those changes have been pushed already. In this case, the push will fail, and git will ask you to pull first.

Case 3: Standard merge

This happens when your changes affect different files or if you changed a file, like your daily note, in two distinct locations on two different devices. For example, you change the top paragraph of your daily note on your main computer and forget to push those changes. Then, on your smartphone, you change the very last paragraph and push these changes. Back on your computer, you want to push, and it fails (but your local changes will be committed locally). Since git asks you to pull first, you pull.

  • The notification will be the regular, small “… Changed n files” notification
  • git will merge the changes and commit them
  • the next time you push, this merge will be pushed along with the other changes you will have made by then

Case 4: Merge fails with conflict markers in affected files

This is a tricky one since the plugin gives you no clear indication that it happened. That means:

Appendix A: Testing merge

First, we create a new branch in our Zettelkasten, so we can play around without causing permanent damage:

Appendix B: Future-proofing the Android scripts

Here, we will tidy up our scripts — so they become cross-platform friendly — and we don’t get any surprises if we replace them with some other script we developed for another system.

Problem with widgets: /usr/bin/env does not exist

So consider log.sh:

How and why this works

The source of the solution is termux-exec.

--

--

Software engineer turned researcher, AI heavy data scientist with strong computer science and electronics skills.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rene Schallner

Software engineer turned researcher, AI heavy data scientist with strong computer science and electronics skills.