0

Along the code there could be very sensitive information such as passwords, amazon s3 keys, etc that I don't want to be sent to git at all.

I'd like those very specific fields to either be replaced with "SECRET" or something like that. Also, is git private repo solving this?

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • 1
    The answer is not to put things like that in tracked files. I'll suggest a few duplicates... – Cascabel Dec 03 '11 at 06:26
  • Also http://stackoverflow.com/questions/2154948/how-can-i-track-system-specific-config-files-in-a-repo-project/2155355#2155355 – Cascabel Dec 03 '11 at 06:28
  • @RailsN00b: check the edit on the answer. I don't think you want what I added, but just in case... – Throoze Dec 03 '11 at 06:46

1 Answers1

3

Since git tracks text and not just files, replacing these lines with some other text would be interpreted by git as a change on the code, so it would overwrite the original sensitive info in the next commit.

What I use to do in these cases is to modularize my code so this info get isolated in a single file, and then I add a line with the file name to the .gitignore file.

The .gitignore file is a collection of patterns, one per line, of file names to be ignored by git while tracking changes in your repo.

For example, if I'm writing a web system in php, I create a file that only store info about credentials for connecting to the database (frameworks use to do so too, so you could guess it's a good practice...). So I write this file once with the test server credentials (which my collaborators are supposed to know) or with some dummy credentials, commit it and push it to my remote, and then I add the file name to my .gitignore.

In the other hand, you have the command git add -p, which interactively let you skip lines, but that would result on a file without the mentioned lines in your remote repo, an you having to manually skip the lines every time you add the file...

A Good reference for git is Progit. Highly recommended if you are starting with git... Also, Github's help center is a very good place to look.

I hope it would be helpful! good luck!!!

Throoze
  • 3,988
  • 8
  • 45
  • 67
  • 2
    An addition to this that we used to do is to have a version of that file with the right structure, but without any sensitive data, saved as a '.template' file next to where the real one should be. Then when you have a new team member, or hose your repo and have to reset it or something, you can just copy the file and fill in the blanks. You can also do this for project files that contain paths... – MattJenko Dec 03 '11 at 06:55
  • @MattJenko: I've never done that! it's a pretty good idea! thanks! =) – Throoze Dec 03 '11 at 07:08