Thanks to:
- This tutorial from Atlassian
- that originated from this HackerNews thread by StreakyCobra
- that brought me to an older article about the same technique
Personal alias:
alias homegit='GIT_DIR=$HOME/.homegit/ GIT_WORK_TREE=$HOME git'
To be used in scripts using shellcheck SC2262:
homegit() { GIT_DIR=$HOME/.homegit/ GIT_WORK_TREE=$HOME git "$@"; }
$ brew install git-crypt
$ cd $HOME/.homegit
$ git-crypt init
Generating key...
$ GIT_DIR=$HOME/.homegit/ GIT_WORK_TREE=$HOME git-crypt add-gpg-user 0xA0A378A5
[main cce002a] Add 1 git-crypt collaborator
2 files changed, 4 insertions(+)
create mode 100644 .git-crypt/.gitattributes
create mode 100644 .git-crypt/keys/default/0/85FB93CFF14B5E412120735503E546AEA0A378A5.gpg
$ echo 'npmrc filter=git-crypt diff=git-crypt' > ~/.gitattributes
$ cd
$ config add .npmrc
$ config commit -m 'Add .npmrc (encrypted)'
$ brew install gpg
You can copy the private key from 1Password and import it:
pbpaste | gpg --import
Now you can run (it will ask for the passphrase):
homegit crypt unlock