git-cryptx

Automatically encrypt/decrypt sensitive files in Git repositories.

Visit our GitHub repository: git-cryptx

Features

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:

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:

  1. Search for "Environment Variables" in the Start menu.
  2. Click on "Environment Variables".
  3. Under "System variables", find the Path variable and click "Edit".
  4. Add the path to your project's target/release directory.
  5. Click "OK" to save changes.

Install via 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

  1. Initialize repository: git-cryptx init
  2. Set encryption key: git-cryptx set-key <your-key>
  3. Configure files to encrypt (edit .gitattributes and the file must not be encrypted):
  4. 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

How It Works

git-cryptx uses Git's filter mechanism to automatically encrypt and decrypt files:

  1. When files are added to Git, the clean filter encrypts content.
  2. When files are checked out, the smudge filter decrypts content.
  3. Files remain in plaintext in the working directory.
  4. Files remain encrypted in the Git repository.

Security Notes

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:

  1. If you are sure that the local file has not been modified, just the decryption status is different:
  2. git-cryptx reset 
  3. If the local file has indeed been modified:
  4. # Store local modifications
    git stash
    # Pull updates
    git pull
    # Restore local modifications
    git stash pop
  5. If conflicts occur, resolve them manually before committing.

Team Collaboration

When a new team member joins the project, follow these steps:

  1. Clone the repository: git clone <repository-url>
  2. Initialize git-cryptx: git-cryptx init
  3. 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>
  4. Check configuration status: git-cryptx status
  5. Update working directory files:
  6. # Clean working directory
    git clean -fd
    # Checkout files to trigger decryption
    git checkout .

Important notes:

Contributing

Pull requests and issues are welcome.

License

MIT License