3

How two organize two projects that have common part of code ?

I have 2 projects that have common part of code, that is being changed from time to time. I use TortoiseGit.

For example

project 1 - master
project 2 - dev-branch. 

As I understand when I make changes in dev-branch (changes in specific dev-branch code and in common with master code) and then merge master with dev-branch, master will get also specific dev-branch code.

How do I resolve this situation to get, for master, only master specific changes?

Taryn East
  • 27,486
  • 9
  • 86
  • 108
pvllnspk
  • 5,667
  • 12
  • 59
  • 97

3 Answers3

4
  1. You have to have an additional repository for the code you have in common. So in your case in total you'll have super-project1, super-project2, and a new sub-project repository.
  2. For any of the files you want to be in the shared project, you must collect them into a special special sub directory (or tree) such that none of the super-project files are contained in the shared code directories.
  3. After strict separation you can use Git's submodules or git-subtree (Use Case of subtree, identical to yours)
johnb003
  • 1,821
  • 16
  • 30
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
1

you could use submodules for this

--edit correcting link

Máté
  • 2,294
  • 3
  • 18
  • 25
  • Link is dead - a submodule tutorial for the command line: https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial - In TortoiseGit it's just right-click, Add Submodule. – Chris Moschini May 15 '13 at 01:25
1

You can even have a git repo inside of a git repo, but you will end up 2 histories. I chose this option myself because I always change my inside git repo as a block since I want to update its unit tests whenever I update that repo.

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29