tags:

views:

160

answers:

3

My git repo contains sensitive passwords which, for reasons out of my control, can't be removed right now. Right now it's all OK because this repo is internal-only, but I've been asked to create a branch that's safe to share with partners.

Is there any way to create a branch in git and then remove files from it in a way where they can't be retrieved using the log?

Seems like a long shot, but thought I'd ask. The only solution I can think of is to copy the file tree to a new git repo without the sensitive file--but then I'd lose the ability to merge partner changes back to my repo.

+4  A: 

One thing you could do is create a branch of your repo, edit out the passwords, and then create a shallow clone (with depth 1) of that repository that you would give to the partners. They can make patches and whatnot against that clone, but can't see the whole history and can't push the repo anywhere else. If they're just making changes, then this should be a workable solution. You can still accept patches from them and apply to your master repository.

See the --depth option of git clone for further information.

Greg Hewgill
I think this solution will work better for Ben's situation. It's easier to manage access on a repository basis, than on a branch basis.
Apreche
+3  A: 

Use filter-branch:

Suppose you want to remove a file (containing confidential information or copyright violation) from all commits:

git filter-branch --tree-filter 'rm filename' HEAD

1800 INFORMATION
1.) `--index-filter` should be faster than `--tree-filter`for removing files. 2.) if you don't want to change repository, first create new branch, and rewrite it.
Jakub Narębski
Yes, there is a very good discussion of the various techniques in the documentation I linked to
1800 INFORMATION
A: 

I'll take a stab at a couple answers. Let us assume that you can create a branch that doesn't contain sensitive data. You cloud then make a shallow clone of the branch which would not contain history and therefore you could not pull from it, but it could pull form you.

The other thing would be to clone a new repository and use the git removal tools to expunge sensitive data. This would create a distinct repository that could not interact except through patches with the first, but would have all the history.

John F. Miller