1

I'm writing a web development tutorial. In it, a student starts in a git branch called 'chapter-1-start' and when she finishes the steps in that tutorial chapter, her code should look substantially the same as the code in 'chapter-1-complete.' I'd like to include 'chapter-1-complete' inside a the 'chapter-1-start' branch in a directory like 'lib/reference_app' so she can compare or, if necessary, cut and paste files from complete to start. Here are my goals:

  1. Keep all the code in one repository.
  2. Reference branch 'chapter-1-complete' inside 'chapter-1-start' should be current -- not have to update.

I think this is possible with submodules, but have no experience with them. I'm wary of losing my entire git history by putting in a recursive reference.

Schadenfred
  • 136
  • 1
  • 9

1 Answers1

2

Adding the same repo as a submodule for a particular branch is a trick I have done in the past: see "Copying Doxygen Documentation from gh-pages branch into a subfolder of Master branch" as an example.

In your case, the student can, in his/her own repo, do:

git branch chapter-1-complete origin/chapter-1-complete
git checkout chapter-1-start
git submodule add -b chapter-1-complete -- /remote/url/of/your/own/repo
git commit -m "ADd chapter-1-complete branch as submodule"
git push

Then a simple git submodule update --remote done in chapter-1-start will be enough to update the content of the chapter-1-complete subfolder (root directory of the submodule). See "git submodule follows branch".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So let's say I wanted the chapter-1-complete branch to live in 'lib/reference/', I'd ask a student to cd into lib/reference and then do 'git submodule add...'? This might be too complicated for my target audience, but I very much appreciate your answer. – Schadenfred Jul 04 '18 at 05:30
  • That's it, yes. That could be scripted, in a global shared path, for your intended audience to use. – VonC Jul 04 '18 at 05:33