1

I'd like to get some advices to best handle and version control projects, which exhibit the following structure:

From a parent project (shared among many projects), I need to get a given directory structure and files, i.e.

.
|-- modules/
|    |-- file_1_parent.py
|
|-- controllers/
     |-- file_2_parent.py

From this parent project, several children dependents are derived, which add files to the directories.

The situation then could look like the following (the name of the projects to which the files/directories belong are in parenthesis)

.
|-- modules/                  (parent project)
|    |-- file_1_parent.py     (parent project)
|    |-- file_1_child.py      (child project)
|
|-- controllers/              (parent project)
     |-- file_2_parent.py     (parent project)
     |-- file_2_child.py      (child project)

To be concrete, in my case the parent project is web2py/django project, from which I want to derive several subprojects.

The question is now,

  • How to version control each projects?
  • Should I have a repository for the parent and the child projects separately?
  • Should I some treat the parent project as some kind of package/library?

I thought about the following approaches:

  • Using git submodule or git subtrees: That doesn't work because I of the very rigid directory and file structure I need from the parent project
  • Multiple git remotes in the local project, i.e. two git origins, one to the parent and one to the child project: What speaks against this solution, is that in order to deploy the project somewhere, I cannot just simply run git clone but have to manually set the multiple git remote -v origin.
  • Treating the parent project as a library, which I install via a packet manager, and then either versioning the installed files within the children repositories or put them to .gitignore: Maybe a not solution, which is not so bad, but I don't know a tool for accomplishing that. Maybe there exists a tool which can install a given version from a github repo via some command like some_paket_manager install path/to/git/repo==v.0.0.9
  • Copy&Paste of the files from the parent project: I'm trying to avoid that manual work.
physicus
  • 361
  • 4
  • 12

1 Answers1

1

Just do ordinary merges, the only thing you have to remember is when/if you merge back work on the parent's files done on a child branch to delete the child-project-specific files and changes from the merge result. Git keeps things straight so long as you record what you're actually doing. git diff --diff-filter=A --name-only @ will show you all files added in-flight, e.g. anything brought in by a no-commit merge, so do a no-commit merge, fix up the results to include only the changes you want, commit that, done. Once you get a handle on what fixups need doing you can automate a lot of it, but it won't always be just delete every new file.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • So you suggest to have the parent and the child as branches in the same project? But how am I then be able to share the parent's files as well as their changes among all projects, which depend on the parent? By updating the parent's files in a separate branch, I would need to update the parent's files of each project via "copy&paste"? And thank you very much for your answer!! – physicus Feb 17 '19 at 19:08
  • 1
    you can push and fetch individual histories, names and repo boundaries are all at your convenience. So one way would be a central parent-branch-only repo, whose master you fetch into a "parent" branch in each client's repo, branch/merge from that for the client project as usual and any parent work that winds up being done in a client repo gets extracted as shown in the answer here, pushed back to a staging branch in the parent repo for testing and merging into the master there. – jthill Feb 17 '19 at 20:20