Let’s say I have two projects on github:
- Project 1: a.cpp and c.h
- Project 2: b.cpp and c.h
Now, I could set up two repos, both having c.h. However, this is bad: If I change c.h for Project 1, I need to copy c.h on my hard disk into Project 2 and then push both.
Other solution: Make 3 projects: one for each file. However, people who download Project 1 (with the a.cpp) have to manually download Project 3 (with the c.h) into Project 1’s directory.
Is there any way to make sharing of c.h easy on github?
http://git-scm.com/book/en/Git-Tools-Submodules
Git supports something called submodules that sound like what you would need. In your example, you would have c.h be in its own repository and both projects would include that repository as a submodule. I’m assuming of course that there will be far more things in that submodule than just that one file.
Pitfall: Projects that include submodules usually point to a particular commit in that submodule until and unless you fetch the submodule again and tell your application to use the newest commit (and thus the newest versions of the files).