I'm planning an open source project which I want to publish on GitHub. I want to create several projects which extend each other. But I want the option to change a common base class which should be merged with its parent project but only that shared files the extensions without common files should be independent.
Here are my three example projects:
I want to implement a helpful class called ObservableArray. That class will extend a List which observes with an interface its items and propagates these changes out to registers listeners. This should be useful for multiple projects like my Project B.
I want to implement a SQlite database warper which allows a simple access to a list of rows which are just plain classes. With the help of project A it will be simple to track the changes in the data model which can be simple synced with the SQLite database.
This project should take the database warper and put it into an Android ContentProvider for some other use cases.
As you can see all three Projects are built on top of each other but Project A or Project B but a user may not need the support of ContentProviders so far I want to make that to independent projects. I think it is too much overhead to let the user of project C update all the three independed projects. So my idea was to fork one project the other so that each project can updated or how this is called in GitHub.
I know that are quiet basic questions I tried to understand the basics of git and the fork graph from GitHub let me think that this should be possible but it seems that this only works if you have multiple accounts. Please enlighten me!
It sounds like you're looking for submodules. A submodule basically allows you to point at a specific commit in another git project. In your example you would do something like:
git init
Project B then git submodule add /project/a/url/
git submodule init && git submodule update
At this point you will see project A's code in a sub directory of Project B as if you had git cloned
it into Project B's directory. However, Project B's git repository will now of a .gitmodules
file which contains the URL you used in git submodule add
. Also, now when you do git add project-a-directory
in Project B instead of committing file changes you will commit a pointer to the SHA id currently checked out in the submodule.
You should read up on the documentation, submodules are very useful but can be a bit tricky to get the hang of.
If you make changes in the Project A submodule you cannot commit them from Project B. The project A submodule has Project A's complete git repository. To commit changes you commit them and push to Project A's repository then commit a new pointer to the new SHA in Project B.
If remote changes are made to Project A that you want you can't fetch them via Project B. First cd
to the submodule directory, fetch the changes and checkout the commit you now want Project B to use. Then cd ..
to Project B and commit a pointer to the new SHA id in the Project A submodule.