DEV Community

Joseph Thomas
Joseph Thomas

Posted on

Git help: Merging updates in a classroom repo

I have a repo of lessons that I'm using to teach a React class. (You can see it here).

Each lesson has a few files:

  • a markdown document
  • a test file
  • an exercise file
  • a solution file
  • maybe some sample data

The students will work within the exercise file, building out react components to get the tests passing. Most of their changes will be here, but they will also be changing a few lines in the test file (changing it.skip to it when they are working on a new test.)

Everybody has created their own fork of this repo, and have cloned that. I have an init script that adds the original repo as an upstream remote.

I'm making updates to the main repo as we move along: fixing some typos, and cleaning up the notes. I would like to figure out a way for my students to pull in these updates without losing the work that they have done.

A simple solution is doing git fetch upstream && git merge --strategy-option ours upstream/master - which will pull in all new updates, but opt for the student's work whenever there is a merge conflict.

But, I also want the students to be able to merge in the updates if they choose to do so. One scenario would be if they had been struggling on a particular exercise and wanted to "reset" it.

An ideal tool would be an interactive CLI where:

  • The student runs the 'update-lessons' script
  • For each merge conflict, they can choose to either:
    • Keep their own work
    • Back up their own work, and merge in the new updates. For example, if there's a conflict in ./src/lesson1/exercise.js, they could choose this option and end up with:
      • ./src/lesson1/exercise.js (The updated file)
      • ./src/lesson1/exercise.5-30-2019.js (The work they had already done)

My students are fairly new to git, so I would want to provide them with something simple.

I don't know git well enough to figure this out, but if I were pointed in the right direction I could write some kind of bash script.

Does anyone know of any tools, workflows, or git magic that could do something like this?

Top comments (2)

coreyja profile image
Corey Alexander

So it sounds like you already have a pretty good cli sketched out there!

You have a script that tries up do an merge with upstream.
Then you do a git diff to find only the files with conflicts and loop over them.
Giving the students the option to reset and save a copy, or fix the merge. If they say the fixed it maybe add the file for them

And then once all the files are finished you should be good to merge the final result, potentially giving the students a chance to enter a message!

Any particular bash or git bit that is tripping you up?

goodidea profile image
Joseph Thomas

Not so far! I haven't had time to dig into writing my own script yet. I think this is the approach I'll take -- I just didn't want to dive in without asking around about something that might already do the same :)