1

i'm working on an application with a specific credential ( login , password , serverIP ) ...

for example : File /test.java :

  String RegDomain = "188.XXX.XXX.XXX";
  String RegPassword = "XXXXXXX";
  String RegUser = "XXXXX";

my need is when i commit , and/or push my code i'd like to found that the test.java as following:

  String RegDomain = "YOurDomaine";
  String RegPassword = "YourPassword";
  String RegUser = "UserName"; 

without changing the value on local repository .

MoxGeek
  • 458
  • 6
  • 17
  • You can't handle that with git (at least not easily) but you should encode them. Also you should externalize these credentials and config in a property file. The way to encode will vary depending on which framework you use (if you use any) – Matt Jan 04 '19 at 09:03
  • https://stackoverflow.com/search?q=%5Bgit%5D+store+password+in+repository – phd Jan 04 '19 at 10:17

1 Answers1

3

One general way around this problem is :

  • have the code read these values from a config file or the environment
  • commit a template version of the config file or the script that sets the environment - e.g : some separate config.template or env.template file which contains values such as "YourDomain" or "YourPassword" ...
  • do not commit the file which contains the actual values - e.g : add the config file name (config.json or env.sh or ...) to your repo's .gitignore

With this setup, after the first git clone of your project, the developper would have to run an extra setup step to create the environment to run the program.

LeGEC
  • 46,477
  • 5
  • 57
  • 104