User-Fork upstream sync

Hello everybody

We’re using for an introductory course to programming.

In order to deliver our weekly jupyter notebooks to our students we setup a private course material git repository and a public semester repository. Since teaching a CLI or Git was out of scope for our course we had the students to download and upload the notebooks they worked on every time they started a new session.

This obviously isn’t a great user experience and we started looking into better solutions.

Right from the beginning we’re thinking about a fork based approach, which would automatically sync the student fork with our public semester repository.

Thanks to @rrrrrok we’re able to implement just that in a minimal invasive way.

by adding the following few lines to our semester repository’s

# sync latest changes from upstream fork
# TODO: maybe we'll switch this to main in the future

# get current semester
SEMESTER=$(git remote get-url origin | sed -re 's/https\:\/\/renkulab\.io\/gitlab\/.+\/(.*)\.git/\1/gi')

# add upstream remote
git remote add upstream${SEMESTER}.git

# make sure we're in master branch
git checkout ${REMOTE_BRANCH}

# fetch and pull changes
while true; do
    git fetch upstream
    if [ $? -eq 0 ]; then
        git pull upstream ${REMOTE_BRANCH}

# sync back to origin
git push origin ${REMOTE_BRANCH}

we could ensure, that students will get the latest changes every time they start a new session.

I post this here incase someone else has a similar problem. Feel free to reach out if you need assistance.

1 Like

Thanks @noeleont for this nice write-up! It’s quite a simple solution in the end but also something that I think a lot of course instructors struggle with. We could potentially think about automating this further or maybe even making it a project setting. The problem is that for non-public projects I don’t think we have a good way of querying the gitlab api for the fork relationship from the container so it might have to be baked into the project’s metadata.