跳至内容

Junyi's Lab

🔐 使用 git-crypt 加密你的仓库

Table of Contents

git-crypt enables transparent encryption and decryption of files in a git repository.

Here is a demo of how to use git-crypt to encrypt files in a git repository.

BasicFlow

# Step 1: Install git-crypt

brew install git-crypt
git-crypt init # in an initialized git repository

Specify files to encrypt by creating a .gitattributes file:

# The config is similar to .gitignore
accounts/*.bean filter=git-crypt diff=git-crypt
*.md         filter=git-crypt diff=git-crypt
*.png        filter=git-crypt diff=git-crypt
*.jpg        filter=git-crypt diff=git-crypt
*.excalidraw filter=git-crypt diff=git-crypt
*.txt        filter=git-crypt diff=git-crypt
*.pdf        filter=git-crypt diff=git-crypt
*.json       filter=git-crypt diff=git-crypt

# Making sure that .gitattributes is never encrypted. DON'T TOUCH THAT LINE AND ONE BELOW
.gitattributes !filter !diff

# Step 2: Add files

git add .
git commit -m "Add git-crypt"
git push

# Step 3: Check git-crypt status

  • git-crypt status -e Show encrypted files only
  • git-crypt status -u Show unencrypted files only
  • git-crypt status -f Fix problems with the repository

# Results

The beancount file is encrypted.

Alt text

# 后续更新

## 1 月 30 日更新

我乱玩,把自己锁死了。

这个傻逼工具,是可以在你不 export symmetric key 的情况下,允许你 lock 仓库的。

然后我就在没有 export symmetric key 的情况下,把自己锁死了。

文件没有备份,因为我为了“安全”,只保留了加密后的 commit,历史的提交日志都删了。

😊 真是愉快的一天呢