1

Is there a way to commit a file into a git repo exactly one time and then effectively make the file read-only as far as the repo goes?

For instance, I have a configuration file that contains some credential information that I don't want stored in a repo but I want the structure of the config file itself stored as a template for the next person who checks out the repo to re-hydrate.

Is this something that can be done at the repo level?

RMHarris157
  • 269
  • 2
  • 9
  • 2
    Don't store the configuration file in the repository. Put its name in `.gitignore`, remove it from the index and commit if it was committed before. Store in the repository a sample configuration file with a name that has a different termination or a suffix (usually `.dist` is added to the name). Fill the sample configuration file with default values, where possible, and empty or dummy values for sensitive information like usernames, passwords etc. Add enough comments (use a file format that allows them) to make it easy to be customized. – axiac Feb 08 '17 at 21:16
  • Possible duplicate of [How to make changes that only i can see?](http://stackoverflow.com/questions/2749726/how-to-make-changes-that-only-i-can-see) – max630 Feb 09 '17 at 23:44

1 Answers1

0

This is a pretty common use-case with projects, and should not be done the way you are specifying.

A more ideal approach would be creating a sample properties file, and not including a real one one in git.

Create a file named like project.sample.properties

# Local Configuration
user =
pass = 

# Defaults
server = example.com

Then with git, you would commit the sample, and ignore the user's.

In your .gitignore

project.properties

And make the commit

$git add .gitignore
$git add project.sample.properties

As part of the environment setup instructions, you should specify that local configuration must be done, or add an enforcement to a maven / ant build script.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123