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)
-
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
.
- For windows just copy the executable from this repository into
-
Create a
.gitattributes
in your working repository, then write for example:serverless.yml filter=git-crypt diff=git-crypt
which usually contains important secrets.
-
Run
git-crypt init
to initiate the encrpytion config. -
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 ...
-
The encryption only takes place when we git commit.
-
Since someone in your team needs the credential, let's create a key for decrpytion:
git-crypt export-key ./git-crypt-key
-
Make sure to add
git-crypt-key
to.gitignore
-
Now push the code to the repository.
From Other Machine
-
Pull the repository.
-
Get the
git-crypt-key
file from repository owner. -
Run
git-crypt unlock ./git-crypt-key
in the working directory. -
Now files get decrpyted, and the decryption will be automatic for every
git pull
.