boulder_ruby
boulder_ruby

Reputation: 39695

How can I use the .git/info/excludes to prevent secure files like development.sqlite3 from being pushed to certain repositories but not others?

I just put a private repository of mine hosted on bitbucket for a small rails application into the public domain--into a public github repo. The private repository included the db/development.sqlite3 file for convenience and backup purposes. Seeing that a have a small number of users on my application now, I don't think its responsible to have their email addresses, etc available in the public domain. For now I've gone ahead and removed the cached development.sqlite3 file from the git repository and pushed those changes to both repos. I'd like to continue to push the sqlite3 database to my private repository, however. Its very convenient for my tiny little app.

I've found a number of disappointingly vague references to the .git/info/excludes file as a way to potentially prevent git from pushing certain files to certain repositories, namely here (SO question) and here.

I'm not even sure if these "solutions" would even allow me to do what I'm trying to do, namely, cause git to ignore certain file types for one repository but not for another within the same commit. It doesn't even seem logical. So maybe this is impossible. Please advise.

note: If this question has no answer, i.e. if it is not possible via the above referenced method or otherwise, comment if you like on whether you think I should just take down this question altogether. I'm ambivalent.

Upvotes: 0

Views: 20

Answers (1)

ElpieKay
ElpieKay

Reputation: 30878

Maybe it could be implemented through a post-checkout hook.

Do not push the sqlite3 database to your private repo either. Store it somewhere in your local machine. Make a post-checkout hook, which can copy the database into your repo when you run git checkout in your git repo.

For now I've gone ahead and removed the cached development.sqlite3 file from the git repository.

Just a remind, I wonder if you have removed the database from the whole commit history. If you don't mind it could still be checked out, just ignore it.

Reference:

post-checkout

This hook is invoked when a git checkout is run after having updated the worktree. The hook is given three parameters: the ref of the previous HEAD, the ref of the new HEAD (which may or may not have changed), and a flag indicating whether the checkout was a branch checkout (changing branches, flag=1) or a file checkout (retrieving a file from the index, flag=0). This hook cannot affect the outcome of git checkout.

It is also run after git clone, unless the --no-checkout (-n) option is used. The first parameter given to the hook is the null-ref, the second the ref of the new HEAD and the flag is always 1.

This hook can be used to perform repository validity checks, auto-display differences from the previous HEAD if different, or set working dir metadata properties.

Upvotes: 1

Related Questions