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:
- Implement Project A
git init
Project B thengit 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. Thencd ..
to Project B and commit a pointer to the new SHA id in the Project A submodule.