Github strategy for keeping one version of file private

gitgithub

I am a lecturer writing coding problems for students. What I want to do is give the students the boilerplate code with placeholders for the functions which students are to complete. I will give the students access to a private github repo to clone this.

However, I also want a version of the codebase, complete with sample solutions. Obviously I don't want the students to have access to the solution (until the assignment is over).

I have thought about branches, but AFAIK, I can't keep one branch private.

Maybe I could fork the project into another private repo, but am unsure how I might keep the projects in snyc (apart from the file which contains the solution).

Is there a workflow for this situation?

Best Answer

What could be quite doable:

  • Create 2 repositories: student and teacher.
  • Clone them to your machine (can be done with Github client)
  • You work only in teacher, never touch student.

So your directory structure is 2 cloned git repo's:

  • /student (with a .git folder)
  • /teacher (with a .git folder)

You put markers around the "private" code in comments for your language, example javascript below. The markers indicate where the private code starts and ends.

function sum(a, b) {
  // -----------------------START
  return a + b; // so this is what you expect from the student
  // -----------------------END
}

console.log(sum(1,1)); // I expect 2 as a result of your homework

Then make a simple script on your local machine:

files.forEach((fileContent, fileName) => {
  let newFileContent = '';
  let public = true;
  fileContent.forEach((line) => {
    switch(line) {
      case '// -----------------------START':
        public = false;
        break;
      case '// -----------------------END':
        public = true;
        break;
      default:
        if(public) {
          newFileContent = newFileContent + line + "\n";
        }
    }
  });
  writeFile('../student/' + fileName, newFileContent);
});

It will: take all your files and copy the contents to /student (overwriting) without the private marked parts of the code. If you want you can insert empty lines there but that might give a hint about what kind of solution your expect.

It's untested example code, so likely you have to do some debugging.

Now only thing you have to do is commit and push in the student repository when you are happy about the output. That can be done in one click when using the GitHub client (so you can do a quick visual review) or just do it manually on command line.

The student repo is an output repository only so it will always stay up-to-date, it's clear to the students what's changed by looking at the commits (because they only show changes) and it's simple to handle.

One step further would be to create a git commit-hook which auto-runs your script.

Edit: See you made an edit to your post:

Obviously I don't want the students to have access to the solution (until the assignment is over).

I suspect it's clear but to be complete: Just remove the tags around the finished exercise will publish the answer the same way as you would do for normal updates to the exercises.