0%
July 27, 2024

Git-Crypt Study

git

There are multiple reasons for encrpyting important files in order not to expose it to other people. Let's follow the following step:

On your Machine (before pushing to existing directory)

  1. Let's install git-crypt.

    • For windows just copy the executable from this repository into
      C:\Program Files\Git\cmd
    • For Mac just run brew install git-crypt.
  2. Create a .gitattributes in your working repository, then write for example:

    serverless.yml filter=git-crypt diff=git-crypt

    which usually contains important secrets.

  3. Run git-crypt init to initiate the encrpytion config.

  4. Run git-crypt status to check which files get encrypted. In my case:

    ...
    not encrypted: backend/server.ts
        encrypted: backend/serverless.yml
    not encrypted: backend/service/authService.ts
    ...
  5. The encryption only takes place when we git commit.

  6. Since someone in your team needs the credential, let's create a key for decrpytion:

    git-crypt export-key ./git-crypt-key
  7. Make sure to add git-crypt-key to .gitignore

  8. Now push the code to the repository.

From Other Machine

  1. Pull the repository.

  2. Get the git-crypt-key file from repository owner.

  3. Run git-crypt unlock ./git-crypt-key in the working directory.

  4. Now files get decrpyted, and the decryption will be automatic for every git pull.