1

On the program I am developing I am using version control. However, I have a development mode and a live mode, changed by a variable within the program.

Is it possible to branch off of a base development branch that holds that variable change, but when I have modified the program to push the new commits to the master without pushing those original changes switching it to a dev mode?

Master --------Master with Changes, but not Dev Base Variable change
|-Dev Base     ^ 
  |-Changes----|
James Ray
  • 65
  • 1
  • 1
  • 10

2 Answers2

3

You can have a separate "dev" branch and periodically rebase or merge it on top of your master but that may be a lot of work.

Perhaps it would be less maintenance to have a separate file that lives in your .gitignore that specifies things like a development mode?

Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • If I have the file in a .gitignore than I can not have any changes to that file, which on the rare occasions there may be. – James Ray Feb 05 '16 at 16:54
2

Don't keep the configuration related to the environment under git control.

In a simple case it can be one variable, but usually it is a set of parameters, such as database name / user / password, external API credentials and so on. You don't store your passwords and credentials as plain text in the repository, right?

Two common ways to handle this are:

1) Add the configuration file in .gitignore. In the repository you can have the configuration file example, so it is easy to setup the new environment (just copy the example and modify according to the local environment).

2) Keep the variable parameters as environment variables.

Community
  • 1
  • 1
Borys Serebrov
  • 15,636
  • 2
  • 38
  • 54
  • These parameters are in a server side script, I change between one variable on that script to specify which set of variables to grab. I can not add it to the .gitignore in the rare case I do need to edit the file. I have thought about adding the parameter as an environment variable, however I do not have control over the server enough to change the environment variable. (This is a PHP program) – James Ray Feb 05 '16 at 16:57
  • 1
    @JamesRay are you running your script with Apache or ngnix? It can be possible to set environment variable from configs (check http://stackoverflow.com/questions/2378871/set-application-env-via-virtual-host-config-and-read-this-in-php and http://stackoverflow.com/questions/8098927/nginx-variables-similar-to-setenv-in-apache). Also how do you deploy the new versions? You could have your deployment script to generate the configuration for production. – Borys Serebrov Feb 05 '16 at 17:06
  • I am running Apache, I may be able to use that link, and base the variable based on server URL. I was trying to avoid this for fear the URL is changed. I may have to do this since it appears what I want with git is not possible. Thank you. – James Ray Feb 05 '16 at 17:21