Is it possible to automatically encrypt files via ‘git push’ before transferring to a remote repository? And automatically decode them while ‘git pull’.
I.e, if I have some remote server with shared access with git repository there, and I don’t want our project to be stolen without a permission…
Maybe there is some special git-hooks before push and after pull?
Yes and no.
You could try to depend on hook but that supposes they are installed at the remote locations, and that is not always reliable.
Another way to achieve almost the same effect would be by using a smudge/clean attribute filter driver, but not for a full repo.
(Source: Pro Git book: Customizing Git – Git Attributes)
That way the smudge script is able decode the files, while the clean script would encode them.
Again, that could work for a few sensitive files, not for a full repo.
Off course, those scripts would not be in the repository itself, and would be managed/communicated by another way.
As Alkaline points out in the comments, that idea does not scale for a repo, as the main git maintainer Junio C. Hamano comments back in 2009:
Even though it does not scale to a full repo, the idea was implemented (3 years later in 2013) with
git-crypt, as detailed in Dominic Cerisano‘s answer.git-cryptuses a content filter driver (implemented in cpp, withcommands.cppsetting up your.gitattributeswith the relevantsmudgeandcleanfilter commands).As any content filter driver, you can then limit the application of
git-cryptto the set of files you want, in the same.gitattributesfile:As mentioned in the
README:(see more at spwhitton/ tech/ code/ git-remote-gcrypt, from Sean Whitton)