From 15b193663b7de1dcd659c1cb78940d1bd5eb7e64 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Wed, 11 Jan 2023 14:55:38 +0100 Subject: [PATCH] Add git-merge and slide on merge conflics - day1: Adds a new Lab in git branch section with a git merge - day2: Adds a Slide explaining Merge Conflics before we simulate one --- day1/05_Branching/01_Intro.md | 50 +++++++++++++++++++++++++++-- day2/01_Workflows/02_Centralized.md | 30 ++++++++++++++--- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/day1/05_Branching/01_Intro.md b/day1/05_Branching/01_Intro.md index 0a12d20..0e428fc 100644 --- a/day1/05_Branching/01_Intro.md +++ b/day1/05_Branching/01_Intro.md @@ -14,7 +14,7 @@ environment. * Main branch * Note: Historically it was `master`, many vendors are now moving to `main` * Develop a new feature in a dedicated branch -* Put fixes into the main branch (production) +* Merge fixes into the main branch (production) * Continue to work on the feature !SLIDE smbullets @@ -26,6 +26,8 @@ environment. * List branches * `git checkout` * Switch between branches +* `git merge` + * Incorporates commits from a branch into the current one ~~~SECTION:handouts~~~ @@ -35,6 +37,8 @@ environment. `git checkout` will switch between branches. +`git merge` incorporate commits from one branch into the current one. + ~~~ENDSECTION~~~ @@ -170,6 +174,48 @@ when working with branches quite often. $ git checkout -b feature/docs2 +!SLIDE smbullets +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Merge the branch + +* Objective: + * Use `git merge` to merge the new branch +* Steps: + * Change into `$HOME/training` + * Modify the `README.md` and commit the change + * Switch to the main branch + * Use `git merge feature/docs` to merge the branch + +!SLIDE supplemental solutions +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution +**** + +## Merge the branch + +**** + +### Checkout the main branch + + @@@ Sh + $ cd $HOME/training + + $ git checkout feature/docs + $ vim README.md + $ git add README.md + $ git commit -m "Update README" + +### Merge the branch + + @@@ Sh + $ git checkout main + $ git merge feature/docs + +~~~SECTION:handouts~~~ + +**** + +~~~ENDSECTION~~~ + + !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Delete the branch @@ -177,7 +223,6 @@ when working with branches quite often. * Delete the previously created branch * Steps: * Change into `$HOME/training` - * Switch to the main branch * Use `git branch -d` to delete the selected branch * Bonus: * Try to delete the branch you are currently on @@ -235,4 +280,3 @@ when working with branches quite often. @@@ Sh $ git checkout main $ git branch -d main - diff --git a/day2/01_Workflows/02_Centralized.md b/day2/01_Workflows/02_Centralized.md index c3b8f04..c4a7571 100644 --- a/day2/01_Workflows/02_Centralized.md +++ b/day2/01_Workflows/02_Centralized.md @@ -71,6 +71,31 @@ for integrating and sharing code changes between repositories. **** +~~~ENDSECTION~~~ + +!SLIDE smbullets +# Centralized Workflow - Merge Conflicts + +* Conflicts arise when the same lines in a file have changed +* When merging Git will try to automatically integrate new changes +* Git cannot automatically determine what is correct + * `>>>` marks conflicts and show the differences + * `===` is the barrier between the two states + +Important: those markers need to be deleted from the files + +Example: + + @@@Sh + <<<<<<< HEAD + What is on HEAD + ======= + What is on other branch + >>>>>>> other-branch + +~~~SECTION:handouts~~~ + +**** ~~~ENDSECTION~~~ @@ -194,8 +219,6 @@ in a non-fast forward fashion is not allowed. * Resolve possible merge conflicts, add them * Continue with `git rebase --continue`, push rebased history -Hint: `>>>` marks conflicts and show the differences on merge/rebase. - ~~~SECTION:handouts~~~ **** @@ -273,6 +296,3 @@ Resolve the conflicts, add the file and continue the rebase. ### Push the changes to the remote repository $ git push origin main - - -