0

Suppose the project has following folders:

  • core
  • src

And have branches: master and testbranch

src in master and src in testbranch contains different content.

I want to tell git not to merge the src folder when merging master and testbranch.

In other words, I want to merge only the core folder between branches.

Also, I want git to track the src folder for individual branches just like usual files.

Is there any possible solutions?

prium
  • 167
  • 11

3 Answers3

1

As per my experience it's not possible using a single repository. You can use a git sub-module into your main branch. So your src folder will be as your git submodule. and the project folder will be as your main repository which will contain the core as well the src folder which is actually a git submodule. ( Or vice-versa )

Shahjahan Jewel
  • 2,301
  • 24
  • 23
0

This is not possible afair.
Maybe you should split up core and src into different Git repositories to track them separately.

Vampire
  • 35,631
  • 4
  • 76
  • 102
0

I assume that you know what you are doing, that you are familiar with git concepts and that you are forced by circumstances (upper management or whatever) to do this. It is very against git ways.

That said...

Answer

src in master and src in testbranch contains different content.

Then you should not have them in the same directory.

Make your directory structure like this:

core
src_master
src_testbranch
src --> src_master

src is then a symlink pointing to either src_master or src_testbranch depending on which branch you are in.

Now everything will work fine. The two src_... directories will show up in both branches, but you can just ignore that. You will still just work with src.

It is up to you whether you put the src symlink in .gitignore or not (depends on what you actually want to achieve with all this). Either way it does not matter much.

N.B.: you do not need to call the src_... directories after their branch names, rather name them by whatever is actually in there. You can also put them wherever else, like dist/... or vendor/....

AnoE
  • 8,048
  • 1
  • 21
  • 36