Assumptions
- git is installed, and avaiable on PATH
- git-crypt is installed, and avaiable on PATH
- Repository of interest is at
~/repo - Valid GPG key. See Creating Importing and Exporting GPG Keys to create/import one
Steps
- Configure your Git repository
cd ~/repo
git-crypt init- Specify files to encrypt using
.gitattributesfile:
# Encrypt all files with name secretfile
secretfile filter=git-crypt diff=git-crypt
# Encrypt all files matching *.key, e.g., private.key
*.key filter=git-crypt diff=git-crypt
# Encrypt all files under folder secretdir recuvely
secretdir/** filter=git-crypt diff=git-crypt
# Don't encrypt matching files, e.g., .env-backup-example
*env*-example* !filter !diff
- Add your GPG key to your repo. Replace
$USER_IDwith your GPG id, e.g.,E1555F86885827379EC58C595EFCCCB6B24FD9FA
git-crypt add-gpg-user $USER_ID- Add and commit your files. It will be automatically encrypted with git-crypt
You may lock and unlock the encrypted files with git-crypt lock and git-crypt unlock, respectively.