4

I am using git as version control for a lot of my projects which apart from source code have a number of reports and sensitive documents.

All my repos are currently private but I wish to make some of them public. As mentioned above, I wish to hide some of the files (or may be directories) from public. Is that even possible? If not, is there a better way of doing this?

3
  • Git stores repository state as a single unit (the commit). It is not possible to hide a part of a commit. Commented Mar 2, 2013 at 21:51
  • Here is an interesting answer on SO that makes use of two repos (public and private portions), but links them locally: stackoverflow.com/a/62213595/5411817. Another answer in same Q suggests using a .gitignore file, though that likely won't be helpful for your own references! Also, .gitignore would not remove files already committed from the history. There is a good post on how to remove specific files from the entire git history, if anyone is interested, I can try to find that post again. Commented Dec 1, 2021 at 18:54
  • You can use some tools like gitexporter to automatically export files from commit history to another open repository.
    – pahaz
    Commented Jan 8, 2022 at 19:23

2 Answers 2

1

Hiding specific information in a git repository is not one of the things it's designed for. AFAIK it is also not possible. One approach that might work, though I have never tried this, is to have a public and a private git repo, and have the private repo be a git submodule for the public one. This might be more hassle then it's worth though, and might be confusing at points causing you to put private data in the public repo. So perhaps you should just have tow completely separate repos.

6
  • Ok cool. If it's not possible; then well it's not possible. Thanks.
    – p0lAris
    Commented Mar 2, 2013 at 21:56
  • Ok. So I'll have private repos — but say for example I change some files in private that are also part of public — how would I commit changes to both the public and private repos together?
    – p0lAris
    Commented Mar 2, 2013 at 22:00
  • It would be odd to have dependencies going from the public repo to the private repo. If people can't use certain parts of the public one without having access to the private one, there is little point in having these be public no? I'd try to keep all dependencies in the other direction. At least that is my reaction as software developer, though I suspect this applies just as well to documents in general. Commented Mar 2, 2013 at 22:03
  • @flippex17: You can't do that. If you think about it, what could it possibly do with the commit message? Commented Mar 2, 2013 at 22:06
  • 1
    What I have done (it isn't exactly what you ask for, though; git is build for sharing, not hiding) is to have some private branches that aren't shared on which I keep files not for public consumption.
    – vonbrand
    Commented Mar 2, 2013 at 23:12
1

It should be possible by encrypting the files: https://git-secret.io/

Why does encrypting files help:

How does git-secret solve these problems? git-secret encrypts files and stores them inside the git repository, so you will have all the changes for every commit.

Files which are encrypted with public keys cannot be read by other parties which do not have access to the private keys, so they can be safely uploaded to a public repository.*

git-secret is a bash tool to store your private data inside a git repo. How’s that? Basically, it just encrypts, using gpg, the tracked files with the public keys of all the users that you trust.

The tool provides a way to encrypt/decrypt files with multiple public keys (from diff. people).

usage instruction from the git-secret page:

Usage: Setting up git-secret in a repository These steps cover the basic process of using git-secret:

Before starting, make sure you have created gpg RSA key-pair: public and secret key identified by your email address.

Begin with an existing or new git repository. You’ll use the ‘git secret’ commands to add the keyrings and information to make the git-secret hide and reveal files in this repository.

Initialize the git-secret repository by running git secret init command. the .gitsecret/ folder will be created, Note all the contents of the .gitsecret/ folder should be checked in, /except/ the random_seed file. In other words, of the files in .gitsecret, only the random_seed file should be mentioned in your .gitignore file.

Add the first user to the git-secret repo keyring by running git secret tell [email protected].

Now it’s time to add files you wish to encrypt inside the git-secret repository. It can be done by running git secret add command. Make sure these files are ignored by mentions in .gitignore, otherwise git-secret won’t allow you to add them, as these files could be stored unencrypted.

When done, run git secret hide to encrypt all files which you have added by the git secret add command. The data will be encrypted with the public-keys described by the git secret tell command. After using git secret hide to encrypt your data, it is safe to commit your changes. NOTE:. It’s recommended to add git secret hide command to your pre-commit hook, so you won’t miss any changes.

Later you can decrypt files with the git secret reveal command, or just show their contents to stdout with the git secret cat command. If you used a password on your GPG key (always recommended), it will ask you for your password. And you’re done!

* Quantum computing may change this in the future.

1
  • Explaining HOW this tool can solve OPs problem will make this a better answer. Right now this is more of a comment. Commented Mar 5, 2019 at 22:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .