I used the method proposed by GoodDeeds (Thanks!), but in order to merge the two branches, I wrote some scripts (easy to share with the other teachers), that may be useful to others:
A script that merge the branches, by making sure files in FILES_TO_REMOVE
are not present on the student version, and FILES_NOT_MERGED
are not synchronized anymore.
#!/usr/bin/env bash
# This script will move the teacher changes on the student branch... except
# for the solutions and the scripts files.
set -e
# https://stackoverflow.com/questions/4691956/how-to-make-bash-expand-wildcards-in-variables
function expand { for arg in "$@"; do [[ -f $arg ]] && echo $arg; done }
#### /!\ Lines to edit if you add some more files to correct! ####
FILES_TO_REMOVE=$(expand gestion/*)
FILES_NOT_MERGED=$(expand mono.py cesar.py)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" != "master" ]]; then
echo '/!\ Please go first on master branch.';
exit 1;
fi
# Go to the root folder
cd $(git rev-parse --show-toplevel)
# Go on the student branch
git checkout students
# merge but don't commit yet
echo "### If you see some errors on the next line about"
echo "### conflicts with a file that should be removed,"
echo "### it's not important."
git merge --no-ff --no-commit master || true
# Remove files if needed
for FILE in $FILES_TO_REMOVE
do
echo "- Removing file $FILE..."
git rm "$FILE" || true
done
# reset the files we don't want to commit
for FILE in $FILES_NOT_MERGED
do
echo "- Reseting $FILE..."
# Undo changes made on the files
git reset HEAD "$FILE" || true
echo " Checkout..."
git checkout -- "$FILE" || true
done
echo "### Git status:"
git status
read -p "### Is the last git status fine for you? [Y/n] " -n 1 -r
echo # (optional) move to a new line
echo "The reply is '$REPLY'"
if [[ $REPLY =~ ^[^Yy]+$ ]]
then
echo "You are not happy with the last status?"
echo "Then manually fix the conflits/issues,"
echo "eventually commit with:"
echo " $ git commit -m \"Merged master\""
echo "and when you are done come back on"
echo "the master branch with:"
echo "$ git checkout master"
exit 1
fi
git commit -m "Merged master"
echo "### Status of student branch:"
git status
echo "### Checkout back on master:"
git checkout master
echo "########################################"
echo "### Congrats, the branch is synced ! ###"
echo "########################################"
I also wrote a script to automatically push the students
branch on the master
branch of the second remote:
#!/usr/bin/env bash
# This script will push the students branch on the student online repo.
set -e
NAME_REMOVE="students_repo"
DEFAULT_REMOTE="https://gitlab.com/3i024_2020/tme_01_mono_students"
if ! git config "remote.${NAME_REMOTE}.url" > /dev/null; then
echo "### I will add a new remote named 'students_repo'."
echo "What is the adress of this remote? (default is '${DEFAULT_REMOTE}'):"
read -p "" remote
remote=${remote:-$DEFAULT_REMOTE}
git remote add students_repo "$remote"
echo "New remote created!"
fi
echo "### Please, make sure you merged your branch with the student branch with:"
echo "$ gestion/merge_student.sh "
echo ""
echo "### I will now push the students branch on the master branch"
echo "### of the 'students_repo' remote."
git push students_repo students:master
echo "### Done!"