Skip to main content
coreydaley.dev

An encrypted git repo where even GitHub can't read the file names

A private GitHub repo is private from other people, not from GitHub. Anyone who can read GitHub’s storage, or your account, sees every file, every file name and every commit message.

Most of the time that’s fine. For some things it isn’t. I keep my own security research in a git repo: notes and proof-of-concept files that can’t be public until the vendor ships a fix. I wanted the backup and history git gives me, without the host being able to read any of it, the names included.

git-remote-gcrypt does that. Here’s the setup, what the host actually ends up storing, how it compares with git-crypt, and the one rule that will cost you commits if you skip it.

The setup

Everything here was tested on macOS 27.2.1 with git 2.56.1, GnuPG 2.5.24, git-remote-gcrypt 1.5 and git-crypt 0.8.0, all from Homebrew. You need a GPG key with an encryption subkey.

brew install git-remote-gcrypt

gcrypt is a git remote helper. You keep a normal repo on your Mac and point a remote at a gcrypt:: URL. Everything is encrypted on the way out and decrypted on the way in:

git remote add origin gcrypt::https://github.com/<you>/<repo>.git
git config remote.origin.gcrypt-participants <your-key-fingerprint>
git config remote.origin.gcrypt-signingkey <your-key-fingerprint>
git push origin main

The GitHub repo has to exist first; create it empty and private. gcrypt-participants is who can decrypt (list several fingerprints for a shared repo). gcrypt-signingkey signs the manifest, so a clone can tell nobody else wrote it.

The first push says a little more than a normal one:

gcrypt: Setting up new repository
gcrypt: Due to a longstanding bug, this push implicitly has --force.
gcrypt: Consider explicitly passing --force, and setting
gcrypt: gcrypt's require-explicit-force-push git config key.
gcrypt: Encrypting to:  -R 672F56787972A54D
gcrypt: Requesting manifest signature

Keep that --force line in mind. It comes back later.

What the host actually stores

I didn’t want to take “everything is encrypted” on faith, so I pushed a small test repo to a plain bare repo standing in for GitHub, then looked at the host’s side directly. The test repo had a notes file, a contacts file and a 200 KB binary, committed as “Add meeting notes and scan”. The test key was a throwaway.

Here’s everything the host has:

$ git branch
  master
$ git log --all --format='%h %an <%ae> %ad | %s' --date=short
681da0f root <root@localhost> 2012-12-31 | Initial commit
$ git ls-tree -r --long master
585     91bd0c092128cf2e…
200688  c2145249d66fa160…

One branch, called master even though I pushed main. One commit from “root”, dated 2012, with a dummy message. Two files named by hashes:

  • A 585-byte manifest, encrypted to my key. gpg --list-packets shows the recipient as keyid 0000000000000000: gcrypt hides which key it was encrypted to.
  • A 200 KB pack with the actual repo, encrypted with a random key that lives inside the manifest.

Running strings over every object turned up none of my file names, commit messages, my name or my email. What does leak is size and timing: each push adds a pack about as big as what changed, so the host can tell you pushed roughly 200 KB, and when, and how much each later push adds.

A fresh git clone gcrypt::… checked the manifest signature, decrypted, and matched my working copy file for file. My real repo on GitHub has the same shape when I clone it raw, without gcrypt: a dummy commit, files named by hashes, and ciphertext.

The alternative: git-crypt

git-crypt solves a different problem. It encrypts the contents of the files you choose and leaves the repo otherwise normal:

git-crypt init
git-crypt add-gpg-user --trusted <your-key-fingerprint>
echo 'notes/** filter=git-crypt diff=git-crypt' >> .gitattributes

I built the same test repo with git-crypt and pushed it to another bare repo. Here’s the host’s view:

$ git log --format='%h %an <%ae> | %s'
6c9bf02 Test User <test@example.com> | Add meeting notes and scan
68b6a4e Test User <test@example.com> | Encrypt notes, contacts and scans
23bd38b Test User <test@example.com> | Add 1 git-crypt collaborator
$ git ls-tree -r --long main
165     .git-crypt/.gitattributes
304     .git-crypt/keys/default/0/3AF8B4B9121A7FBDA27EDBAF672F56787972A54D.gpg
124     .gitattributes
8       README.md
37      contacts.txt
55      notes/2026-11-meeting.md
200022  scan.bin

The contents of contacts.txt, the notes and scan.bin are encrypted; each starts with GITCRYPT followed by ciphertext. Everything else is in the clear:

  • Commit messages, author name and email.
  • Every file name and folder. notes/2026-11-meeting.md tells a reader a lot before they read a byte of it.
  • Exact sizes. Each encrypted file is its plaintext plus 22 bytes.
  • Who has access. Each collaborator’s key fingerprint is a file name.
  • Anything you didn’t list in .gitattributes, like the README here.

That’s not a flaw; it’s the design. In return you keep a normal GitHub repo: you can browse it, open pull requests, run Actions on the unencrypted files, and share one secrets file in an otherwise public repo. If you want to hide an API key in a project, use git-crypt. If the file names themselves are sensitive, it’s the wrong tool.

The rule you can’t skip: pull before every push

Back to that --force line. The gcrypt manual says it plainly under Known issues: “Every git push effectively has –force. Be sure to pull before pushing.”

I wanted to see what that means in practice, so I made two clones of the same gcrypt repo, standing in for two Macs:

  1. Mac A commits “Note from Mac A” and pushes.
  2. Mac B, which never pulled, commits “Note from Mac B” and pushes.

With a normal remote, git rejects step 2 and tells you to pull. With gcrypt:

To gcrypt::…/repo.git
   393a861..a39f6bd  main -> main

No rejection, even though a39f6bd doesn’t build on 393a861. A fresh clone afterwards shows Mac B’s commit on main and not Mac A’s. Mac A’s commit isn’t destroyed: its encrypted pack is still on the host, and git fsck in a fresh clone finds it as a dangling commit. But no branch points at it any more, so nobody will see it unless they go looking. It also still exists on Mac A. Either way, you can recover it only if you notice.

So the rule is simple: git pull before every push, on every machine.

gcrypt has a setting that sounds like a fix, git config gcrypt.require-explicit-force-push true. I tried it. It refuses every push that doesn’t say --force, even an ordinary fast-forward one (“Implicit force push disallowed by gcrypt configuration”). So it doesn’t detect the overwrite; it makes you type --force each time, as a reminder that’s what you’re doing. That’s worth having on a repo shared between machines, but the pull is still on you.

What else it costs you

  • No GitHub features. No browsing, no diffs, no pull requests, no Actions, no search. GitHub is just storage.
  • Lose the key, lose the repo. No one can recover it, including you. Back the GPG key up somewhere that isn’t the repo, and test the restore.
  • Occasional big pushes. gcrypt can decide to repack the remote and re-upload the whole history without warning.
  • Every clone needs the config. A clone doesn’t keep gcrypt-participants.
  • It hides data, it doesn’t guard it. Anyone with write access to the host repo, or your GitHub account, can still delete or overwrite it. They just can’t read it. Keep a copy somewhere else.

What I got wrong

The clone point nearly fooled me. The first time I ran the two-Mac test, Mac B’s push was rejected, and my first read was that the force-push warning was out of date. Then I read the rest of the output. My second clone didn’t have gcrypt-participants set, so gcrypt fell back to my default key from my global git config, which wasn’t in the throwaway keyring. Signing and encrypting failed (“sign+encrypt failed”), so the push failed too. Nothing was protecting Mac A’s commit. Once I set the participants on that clone, the overwrite happened exactly as the manual says.

Two lessons: set the gcrypt config on every clone, and when a test agrees with what you hoped, read the whole output before believing it.

Which one to use

If you need GitHub’s features and only some files are secret, use git-crypt. If the names and history are themselves the secret, use gcrypt.

What do you keep in git that would tell a stranger more by its file names than by its contents?

Related posts