Automatically encrypt/decrypt sensitive files in Git repositories.
Visit our GitHub repository: git-cryptx
Features
功能特点
- 🔒 Transparent file encryption/decryption
- 🔄 Seamless Git workflow integration
- 🎯 Precise file pattern matching
- 👥 Team collaboration support
- 💻 Cross-platform support
Installation
安装
Build from Source
从源代码编译
To compile the project, use the following command:
cargo build --release
After building, make sure to add the binary to your system's PATH
permanently:
Linux/macOS:
Linux/macOS:
Add the following line to your ~/.bashrc
, ~/.bash_profile
, or ~/.zshrc
file:
export PATH="$PATH:/path/to/your/project/target/release"
Then, run:
source ~/.bashrc # or source ~/.bash_profile or source ~/.zshrc
Windows:
Windows:
- Search for "Environment Variables" in the Start menu.
- Click on "Environment Variables".
- Under "System variables", find the
Path
variable and click "Edit". - Add the path to your project's
target/release
directory. - Click "OK" to save changes.
Install via Homebrew
使用 Homebrew 安装
For macOS users, you can install git-cryptx
using Homebrew:
brew tap ChrisHyperFunc/brew
brew install git-cryptx
brew upgrade git-cryptx
Quick Start
快速开始
- Initialize repository:
git-cryptx init
- Set encryption key:
git-cryptx set-key <your-key>
- Configure files to encrypt (edit
.gitattributes
and the file must not be encrypted):
example.secret filter=git-cryptx diff=git-cryptx
*.secret filter=git-cryptx diff=git-cryptx
config/*.key filter=git-cryptx diff=git-cryptx
sensitive/* filter=git-cryptx diff=git-cryptx
sub_tree_directories/** filter=git-cryptx diff=git-cryptx
如有必要:
.gitattributes !filter !diff
Commands
命令说明
init
: Initialize git-cryptxset-key <key>
: Add encryption keyrm-key
: Remove encryption keystatus
: Show encryption status
How It Works
工作原理
git-cryptx uses Git's filter mechanism to automatically encrypt and decrypt files:
- When files are added to Git, the clean filter encrypts content.
- When files are checked out, the smudge filter decrypts content.
- Files remain in plaintext in the working directory.
- Files remain encrypted in the Git repository.
Security Notes
安全说明
- Uses AES-256-GCM for encryption.
- Keys stored in
.git/cryptx
directory. - Supports file integrity verification.
- Encrypted files marked with magic number.
FAQ
常见问题
Q: How to share keys with team members?
A: Share the .git/cryptx/keys/global_ase_key
file through a secure channel.
Q: How to view differences in encrypted files?
A: git-cryptx supports viewing plaintext differences directly using regular git diff.
Q: What to do if git pull prompts that local files will be overwritten?
A: You can resolve this by:
- If you are sure that the local file has not been modified, just the decryption status is different:
- If the local file has indeed been modified:
- If conflicts occur, resolve them manually before committing.
git-cryptx reset
# Store local modifications
git stash
# Pull updates
git pull
# Restore local modifications
git stash pop
Team Collaboration
团队协作
When a new team member joins the project, follow these steps:
- Clone the repository:
git clone <repository-url>
- Initialize git-cryptx:
git-cryptx init
- Obtain the key file from other team members:
- Get the
.git/cryptx/keys/global_ase_key
file. - Place it in the same location in your local repository.
- Or
git-cryptx set-key <your-key>
- Check configuration status:
git-cryptx status
- Update working directory files:
# Clean working directory
git clean -fd
# Checkout files to trigger decryption
git checkout .
Important notes:
- Transfer the key file through secure channels (encrypted email, secure messaging, etc.).
- Never commit the key file to the Git repository.
- Each cloned repository needs its own key configuration.
- If files appear encrypted, the key is not properly configured.
Contributing
贡献指南
Pull requests and issues are welcome.
License
许可证
MIT License