AGWA / git-crypt

Transparent file encryption in git
https://www.agwa.name/projects/git-crypt/
GNU General Public License v3.0
8.11k stars 472 forks source link

Use with bare repo #192

Closed scolby33 closed 4 years ago

scolby33 commented 4 years ago

Is it possible to use git-crypt with a bare repo? I was able to successfully git-crypt init by cd-ing into the .git directory for the bare repo but I am unable to git-crypt add-gpg-user. This is due to the error thrown here: https://github.com/AGWA/git-crypt/blob/master/commands.cpp#L298

In the following lines I see parsing of the git config. Would it be possible to add git-crypt.topLevel or a similar value to bypass the call to git rev-parse --top-level? Would there be other obstacles to using git-crypt with a bare repo other than this particular function?

scolby33 commented 4 years ago

I have found the solution! Using the GIT_DIR and GIT_WORK_TREE environment variables, git-crypt is able to find the proper directories. I hope this will help someone else who has to search for this problem.

mbwgh commented 3 years ago

I did it slightly differently, so maybe this helps too. I have a bare repository which I use via an alias in my .bashrc:

alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'

Since you can use git crypt init etc. instead of git-crypt init, I was thus able to set things up via

config crypt init
config crypt add-gpg-user <my-id>

I put the .gitattributes into $HOME by the way, since this was the path shown by config rev-parse --show-toplevel.

yamsellem commented 2 years ago

@scolby33 thanks a lot!

Running this command line within GIT_WORK_TREE made file decrypted. GIT_DIR=/var/repo/api.git/ GIT_WORK_TREE=/var/www/api git-crypt unlock /etc/whatever/crypt.key