Skip to content

Instantly share code, notes, and snippets.

@mmoya
Forked from bartv2/git-crypt-rekey.sh
Created February 10, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmoya/0f4bbe036d2a2c802476e7db4d4079d1 to your computer and use it in GitHub Desktop.
Save mmoya/0f4bbe036d2a2c802476e7db4d4079d1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Unlock the directory, we need the unencrypted versions of the files
git crypt unlock
# Re-initialize git crypt, generating a new key
rm .git/git-crypt/keys/default
git crypt init
# Make the key available to the current users
KEY_FILES=`ls .git-crypt/keys/default/0/`
for f in $KEY_FILES; do
gpg -e --always-trust -r ${f%.gpg} < .git/git-crypt/keys/default > .git-crypt/keys/default/0/$f
done
# Re-encrypt the files with the new key
ENCRYPTED_FILES=`git crypt status -e | colrm 1 14`
git rm --cached $ENCRYPTED_FILES
git add $ENCRYPTED_FILES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment