7

We have several projects in the works that share a majority of their code/config files. The framework we're using has certain directory and file dependencies that limit us to how much we can segregate common code. For example, between 'common', 'projectA', and 'projectB' we might have:

/projectA

  • /shared_dir1
    • common1
    • fileA1
    • fileA2
  • /common_dir2
    • common2
  • /dir3
    • fileA3
  • common3
  • fileA4

/projectB

  • /shared_dir1
    • common1
    • fileB1
  • /common_dir2
    • common2
  • /dir3
    • fileB2
    • fileB3
  • common3
  • fileB4
  • fileB5

We currently manage this with 3 Git projects: 'common', 'projectA', and 'projectB', with common files separated out into 'common' and project specific files in their own projects. 'projectA' and 'projectB' have a .gitignore with entries for all common dirs and all common files under each shared dir. A script copies 'common' into the project you want to work in and development is done there. Once a change is done, another script copies all common dirs and common files back into 'common'. Changes to 'common' and to the project can then be seen via 'git status'.

This obviously comes with its headaches of copying back and forth between 'common', keeping .gitignore accurate, and switching branches within 'projectA' and 'projectB'. As we plan for 'projectC-F', though, this approach seems nice as we can avoid merging common changes to N projects.

Looking for advice on how to better maintain this type of structure. Submodules seem undoable given the lack of segregation, unless we did a large number of them. I've seen some promising alternatives using symlinks, but that also comes with it's issues. Any advice would be appreciated.

1
  • Did you ever figured out a way to manage your project? Commented Jun 30, 2015 at 21:02

2 Answers 2

2

Have you considered git subtree?

Something like this can be done:

git remote add common git://server/common.git
git fetch common
git checkout -b common_branch common/master
git checkout master
git read-tree --prefix=common/ -u common_branch

Read more in the links below:

http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html

http://progit.org/book/ch6-7.html

Sign up to request clarification or add additional context in comments.

Comments

1

If you're willing to put the shared code in a separate git repository, you might be interested in git submodules. A submodule allows you to include a git repo within another repo.

Here are a couple links:

2 Comments

He mentioned submodules - Submodules seem undoable given the lack of segregation, unless we did a large number of them
Ah, I must have glossed over that last paragraph... Anyway, I think submodules are still a good solution to the problem he describes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.