1

I believe situation I'm describing is pretty common and basic, yet I can't find soultion for it.

I'm developing a web app and I have git repository for it. There is a production version of the app, the code of which I keep on master branch and there are branches for open developments.

What I want to achieve is:

  • I want to have some values (like connection strings) different on master branch and development branches.
  • I want to be able to merge those branches (when the development is reade to be published) in a way I don't worry about values mentioned aboved. So the connection string from development branch doesn't override the connection string from production version
  • The ideal solution would also take care of replacing the connection (from PROD database to DEV) string while creating new branch.

I figured out a way to do it would be a commit with those changes on development branches, that would be marked not to be included in merge, but I couldn't find a way to do it.

I'd appreciate any advice.

Rico
  • 362
  • 1
  • 4
  • 18
  • does [this](https://stackoverflow.com/questions/20078756/making-git-retain-different-section-content-between-branches/20087076#20087076) help? – jthill Jan 01 '18 at 22:37

4 Answers4

3

I suggest that you create some kind of configuration file which is not tracked by git. Your code can read this file to initialize connection settings. Since the file is not under version control, you can easily modify it for different use cases, including production vs development.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • To be more accurate: the configuration files are not tracked *by Git tracking the source code". It is totally fine to have configuration tracked separately in its own SCM – Adrian Shum Jan 02 '18 at 03:26
2

The simplest way is to:

  • version only a template file
  • seek the value files outside the repo (especially for the production value)
    That way, there is no merge issue.

For that, you would register (in a .gitattributes declaration) in your submodule repo a content filter driver.

smudge (image from "Customizing Git - Git Attributes", from "Pro Git book")

The smudge script, associate to the template file, would generate (automatically on git chekcout) the properties file by looking in outside source the actual values. The generated actual properties file remains ignored (by the .gitignore).

See a complete example at "git smudge/clean filter between branches".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

You can ignore files, which you don't want GIT to track by using the .gitignore , read more about it here https://help.github.com/articles/ignoring-files/ .

But this won't solve your issue, as after you add your development phase specific files, then you can't track them to your dev branch as well.

Its a very common scenarios as you mentioned, and normally we create a different file for each stage ie dev,qa,stage,prod , which holds the values specific to a stage.

For example:-

dev.properties :- 
dev server details

qa.properties :-
qa server details

prod.properties :-
prod server details

And then your code , reads these property files based on the phase you select ie dev,qa,prod

Amit
  • 30,756
  • 6
  • 57
  • 88
0

Before making changes for example to the dev. branch, checkout that branch before making changes and then commit.

Diego Francisco
  • 1,650
  • 1
  • 17
  • 31