3

In a git repository, lets say I have a file in my master branch, config.json, which contains some information about e.g. my hosting environment.

master
 - config.json

For the sake of argument, lets assume this file is read by my gulp-file and contains information about whether to minimize my javascripts or include source maps.

In my development branch, I want this file to be different

development
 - config.json

So that whenever I run gulp on my main branch, my javascripts are minimized, whilst when I run gulp on my development branch, I include source maps for my compiled typescript.

Is there a way to ensure that config.json won't be merged from development to master by mistake, and vice versa?

Several generations of source control ago, in Visual Source Safe, this could be achieved by 'pinning' specific files to a specific 'branch'

Is this (or something equivalent) possible with git?

havardhu
  • 3,576
  • 2
  • 30
  • 42

2 Answers2

0

git takes snapshots of your project and do this kind of "pinning" is not a good policy.

There are several solution to do what you want.

BRANCH

Using 3 branches.

  • Official master branch.
  • Official development branch.
  • working branch

You work in the working branch. It can be temporal and the name can be the tracking number of your "Bug/Requirement tracking System".

After finishing, you merge in your Official development branch. Change the specific files to work appropriately. Confirm with your tests that it works.

Come back to the working branch and merge the change in the Official master branch.

SYMBOLIC LINK

If you are in a Unix/Linux machine. You can have two config files. One for master branch and the other for the develop branch.

Then, you create a symbolic pointing in each branch to the corresponding file. Then you can modify indifferently each file without worry of affecting the changes in the other branch.

blashser
  • 921
  • 6
  • 13
  • Thanks for the reply, unfortunately it does not solve my problem. Even if it is not a good policy (an explanation as to why this is not a good policy would be appreciated) I'm still interested in knowing if it is actually possible (using git functionality, not external options such as symbolic links) – havardhu Aug 03 '15 at 20:54
  • The reason of bad policy is that if you want to come back to a previous picture/image/stateOfYourProject it would be impossible because you do not know the changes that this file has had. I am sorry that I could not help you. – blashser Aug 03 '15 at 22:54
0

If you are not interested in the changes of this config file and it is going to be changing. You can remove it of being tracked by git.

git rm yourFile

And after this, you can add it to your .gitignore file to not see it when you do git status or similar commands.

The problem of doing this is that if you clone your project, it is not going to work because this file will not be and you will have to created manually.

blashser
  • 921
  • 6
  • 13