diff --git a/git_series/eth/advanced_course/Makefile b/git_series/eth/advanced_course/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..958fdbf1b270458626ffc78ca3ee36d92ff7f6b6 --- /dev/null +++ b/git_series/eth/advanced_course/Makefile @@ -0,0 +1,12 @@ +TYPST_ROOT!=git rev-parse --show-toplevel +TARGETS=advanced_course.pdf + +all : $(TARGETS) + +.PHONY: watch +watch: + typst w --root $(TYPST_ROOT) $(shell echo $(TARGETS) | sed "s/\.pdf/\.typ/g") + +%.pdf : %.typ + typst c --root $(TYPST_ROOT) $< + diff --git a/git_series/eth/advanced_course/advanced_course.pdf b/git_series/eth/advanced_course/advanced_course.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e6a47e2b87662a2d9ce569c5294daebf88bf0f80 Binary files /dev/null and b/git_series/eth/advanced_course/advanced_course.pdf differ diff --git a/git_series/eth/advanced_course/advanced_course.typ b/git_series/eth/advanced_course/advanced_course.typ new file mode 100644 index 0000000000000000000000000000000000000000..064085f3ae8fd7cbe38df418720effa1010f5dcd --- /dev/null +++ b/git_series/eth/advanced_course/advanced_course.typ @@ -0,0 +1,525 @@ +#import "@preview/touying:0.5.3": * +#import "/typst_template/thealternative.typ": * +#import "@preview/fletcher:0.5.6" as fletcher: diagram, node, edge + + +#show: thealt-theme.with( + aspect-ratio: "16-9", + config-info( + title: [Git advanced course], + subtitle: [], + author: [Ian Wasser], + date: datetime.today(), + institution: [Institution], + ), +) +#show: codly-init.with() + +#title-slide() + += Introduction + +== + +#align(center)[ + #figure(image("../../../typst_template/img/logo_blue.svg", width: 80%)) + + FOSS: Free and Open Source Software +] + +== Organisation + +- Slides and additional material on the website +- Please ask questions +- Theory + Exercises + +== Content + +- Branches + - Merging + - Rebasing + - Remotes +- Best Practices + - Gitignore + - Commiting + - Git Flow +- Large Projects + - Forking + - Pull Requests + - Updating the Fork + += Branches + +== Introduction + +#align(center + horizon)[ + #figure( + diagram( + node-stroke: .2em, + node((0,0), "", radius:2em), + node((1,0), "", radius:2em), + node((2,0), "", radius:2em), + node((3,0), "", radius:2em), + + node((5,0), "main", stroke: stroke(0em)), + + edge((0,0), (1,0), "-|>"), + edge((1,0), (2,0), "-|>"), + edge((2,0), (3,0), "-|>"), + ) + ) +] + +== Introduction + +#align(center + horizon)[ + #figure( + diagram( + node-stroke: .2em, + node((0,0), "", radius:2em), + node((1,0), "", radius:2em), + node((2,0), "", radius:2em), + node((3,0), "", radius:2em), + + node((5,0), "main", stroke: stroke(0em)), + + node((3, -1), "", radius:2em), + node((4, -1), "", radius:2em), + + node((5,-1), "cats", stroke: stroke(0em)), + + edge((0,0), (1,0), "-|>"), + edge((1,0), (2,0), "-|>"), + edge((2,0), (3,0), "-|>"), + + edge((2,0), (3,-1), "-|>"), + edge((3,-1), (4,-1), "-|>"), + ) + ) +] + +== Branch Creation + +```bash +git branch my_branch # Creates a branch called "my_branch" without switching to it +git checkout -b my_branch # Creates a branch called "my_branch" and switches to it + +git branch -d my_branch # Deletes a branch +``` + +== Switching to a branch + +```bash +git checkout my_branch # Switches to the newest version of "my_branch" +git checkout main # Switches to the newest version of the "main" branch +``` + +== Branch Operations + +- Merge +- Rebase +- (Git Cherry Pick) + += Merge + +== Merge + +#align(center + horizon)[ + #figure( + diagram( + node-stroke: .2em, + node((0,0), "", radius:2em), + node((1,0), "", radius:2em), + node((2,0), "", radius:2em), + + node((5,0), "main", stroke: stroke(0em)), + + node((2, -1), "", radius:2em), + node((3, -1), "", radius:2em), + + node((5,-1), "cats", stroke: stroke(0em)), + + // Main Branch + edge((0,0), (1,0), "-|>"), + edge((1,0), (2,0), "-|>"), + + // Cats Branch + edge((1,0), (2,-1), "-|>"), + edge((2,-1), (3,-1), "-|>"), + ) + ) +] + +== Merge + +#align(center + horizon)[ + #figure( + diagram( + node-stroke: .2em, + + // Main Branch + node((0,0), "", radius:2em), + node((1,0), "", radius:2em), + node((2,0), [#image("../../assets/cats/cat5.jpeg")], radius:2em), + node((5,0), "main", stroke: stroke(0em)), + + // Cats Branch + node((2, -1), [#image("../../assets/cats/cat1.jpeg")], radius:2em), + node((3, -1), [#image("../../assets/cats/cat3.jpeg")], radius:2em), + node((5,-1), "cats", stroke: stroke(0em)), + + // Main Branch + edge((0,0), (1,0), "-|>"), + edge((1,0), (2,0), "-|>"), + + // Cats Branch + edge((1,0), (2,-1), "-|>"), + edge((2,-1), (3,-1), "-|>"), + ) + ) +] + +== Merge + +#align(center + horizon)[ + #figure( + diagram( + node-stroke: .2em, + + // Main Branch + node((0,0), "", radius:2em), + node((1,0), "", radius:2em), + node((2,0), [#image("../../assets/cats/cat5.jpeg")], radius:2em), + node((4,0), [#grid(columns:(2em, 2em), gutter:1mm, image("../../assets/cats/cat1.jpeg"), image("../../assets/cats/cat3.jpeg"))], radius:2em), + node((5,0), "main", stroke: stroke(0em)), + + // Cats Branch + node((2, -1), [#image("../../assets/cats/cat1.jpeg")], radius:2em), + node((3, -1), [#image("../../assets/cats/cat3.jpeg")], radius:2em), + node((5,-1), "cats", stroke: stroke(0em)), + + // Main Branch + edge((0,0), (1,0), "-|>"), + edge((1,0), (2,0), "-|>"), + + // Cats Branch + edge((1,0), (2,-1), "-|>"), + edge((2,-1), (3,-1), "-|>"), + + // Merge + edge((2,0), (4,0), "-|>"), + edge((3,-1), (4,0), "-|>"), + ) + ) +] + +== Merge Command + +#grid( + columns:(1fr, 1fr), + gutter:1.5em, + [ + You need to be on the branch you want to merge the specified branch onto. + ```bash + git merge cats + ``` + ], + + grid.vline(stroke:0.1em), + + figure( + diagram( + node-stroke: .1em, + + // Main Branch + node((0,0), "", radius:1em), + node((0.5,0), "", radius:1em), + node((1,0), [#image("../../assets/cats/cat5.jpeg")], radius:1em), + node((2,0), [#grid(columns:(1em, 1em), gutter:1mm, image("../../assets/cats/cat1.jpeg"), image("../../assets/cats/cat3.jpeg"))], radius:1em), + node((3,0), "main", stroke: stroke(0em)), + + // Cats Branch + node((1, -1), [#image("../../assets/cats/cat1.jpeg")], radius:1em), + node((1.5, -1), [#image("../../assets/cats/cat3.jpeg")], radius:1em), + node((3,-1), "cats", stroke: stroke(0em)), + + // Main Branch + edge((0,0), (0.5,0), "-|>"), + edge((0.5,0), (1,0), "-|>"), + + // Cats Branch + edge((0.5,0), (1,-1), "-|>"), + edge((1,-1), (1.5,-1), "-|>"), + + // Merge + edge((1,0), (2,0), "-|>"), + edge((1.5,-1), (2,0), "-|>"), + + // Pointer + edge((3,1), (3,0), "-|>") + ) + ) +) + +== Exercise + ++ Get a working Git repository (easy with `git init`) ++ Create a branch ++ Make some changes to the branch ++ Go to the `main` branch ++ Merge your created branch into the `main` branch + +On the next slide there are some extra guidance commands + +/* +== Exercise Solutions + +```bash +# Create a branch +git checkout -b cats + +# Create a some file + +# Commit the files with +git add . +git commit -m "Added cat images" +``` + +== Exercise Solutions + +```bash +# Go to the main branch +git checkout main + +# Merge the branch +git merge cats +``` +*/ + +== Example Case + +#grid( + columns:(1fr, 1fr), + gutter:1.5em, + [ + File: `story.txt` + ```txt + This is the story of a cat called Gin! + ``` + ], + grid.vline(stroke:0.1em), + figure( + diagram( + node-stroke: .1em, + + // Main Branch + node((0,0), [#text(size:0.75em)[story]], radius:1em), + node((3,0), "main", stroke: stroke(0em)), + ) + ) +) + +== Example Case + +#grid( + columns:(1fr, 1fr), + gutter:1.5em, + [ + File: `story.txt` + ```txt + This is the story of a cat called Gin! + She loves to sleep. + ``` + ], + grid.vline(stroke:0.1em), + figure( + diagram( + node-stroke: .1em, + + // Main Branch + node((0,0), [#text(size:0.75em)[story]], radius:1em), + node((3,0), "main", stroke: stroke(0em)), + + // Cats Branch + node((0.75,-1), [#text(size:0.75em)[sleep]], radius:1em), + node((3,-1), "cats", stroke: stroke(0em)), + + // Cats Edges + edge((0,0), (0.75,-1), "-|>"), + ) + ) +) + +== Example Case + +#grid( + columns:(1fr, 1fr), + gutter:1.5em, + [ + File: `story.txt` + ```txt + This is the story of a cat called Gin! + She plays a lot. + ``` + ], + grid.vline(stroke:0.1em), + figure( + diagram( + node-stroke: .1em, + + // Main Branch + node((0,0), [#text(size:0.75em)[story]], radius:1em), + node((0.75,0), [#text(size:0.75em)[play]], radius:1em), + node((3,0), "main", stroke: stroke(0em)), + + // Cats Branch + node((0.75,-1), [#text(size:0.75em)[sleep]], radius:1em), + node((3,-1), "cats", stroke: stroke(0em)), + + // Main Edges + edge((0,0), (0.75,0), "-|>"), + + // Cats Edges + edge((0,0), (0.75,-1), "-|>"), + ) + ) +) + +== Merge Conflicts + +#grid( + columns:(1fr, 1fr), + gutter:1.5em, + [ + We try to merge + ```bash + git merge cats + + Auto-merging story.txt + CONFLICT (content): Merge conflict in story.txt + Automatic merge failed; fix conflicts and then commit the result. + ``` + ], + grid.vline(stroke:0.1em), + figure( + diagram( + node-stroke: .1em, + + // Main Branch + node((0,0), [#text(size:0.75em)[story]], radius:1em), + node((0.75,0), [#text(size:0.75em)[play]], radius:1em), + node((1.5,0), [#text(size:0.75em)[!]], radius:1em, stroke:(dash:"dashed", paint:red)), + node((3,0), "main", stroke: stroke(0em)), + + // Cats Branch + node((0.75,-1), [#text(size:0.75em)[sleep]], radius:1em), + node((3,-1), "cats", stroke: stroke(0em)), + + // Main Edges + edge((0,0), (0.75,0), "-|>"), + + // Cats Edges + edge((0,0), (0.75,-1), "-|>"), + + // Merge Edges + edge((0.75,0), (1.5,0), "-|>", stroke:(paint:red, dash:"dashed")), + edge((0.75,-1), (1.5,0), "-|>", stroke:(paint:red, dash:"dashed")), + ) + ) +) + +== Merge Conflicts + +Written in `story.txt` there are *conflict markers* + +```txt +This is the story of a cat called Gin! +<<<<<<< HEAD +She plays a lot. +||||||| 8ffed99 +======= +She loves to sleep. +>>>>>>> cats``` + +== Resolving Merge Conflicts + +You edit the content of the file so that it is as wished. + +You can + +- Pick the one from the *current branch* +- Pick the one from the *other branch* +- Pick both and manually merge them + +== Resolving Merge Conflicts + +In our example: We want to *manually merge* them. Hence we change the `story.txt` file into this file + +```txt +This is the story of a cat called Gin! +She loves to sleep and play. +``` + +== Ending the Merging Process + +When you edited *all the conflict files* you can run + +```bash +git add . +``` + +to stage the files in git. To finish the merge you run + +```bash +git merge --continue +``` +#align(center+horizon)[ + #figure( + diagram( + node-stroke: .1em, + + // Main Branch + node((0,0), [#text(size:0.75em)[story]], radius:1em), + node((0.75,0), [#text(size:0.75em)[play]], radius:1em), + node((1.5,0), [#text(size:0.75em)[merge]], radius:1em), + node((3,0), "main", stroke: stroke(0em)), + + // Cats Branch + node((0.75,-1), [#text(size:0.75em)[sleep]], radius:1em), + node((3,-1), "cats", stroke: stroke(0em)), + + // Main Edges + edge((0,0), (0.75,0), "-|>"), + + // Cats Edges + edge((0,0), (0.75,-1), "-|>"), + + // Merge Edges + edge((0.75,0), (1.5,0), "-|>"), + edge((0.75,-1), (1.5,0), "-|>"), + ) + ) +] + +== Aborting the Merging Process + +If you would have wanted to abort the merge you could have also run + +```bash +git merge --abort +``` + +== Exercises + ++ Create a file and commit it to the `main` branch ++ Create a new branch and switch to the branch ++ Write a line into the file you created and commit it ++ Switch to the `main` branch again ++ Write something into the file and commit it to the `main` branch ++ Try to run `git merge branch_name` ++ Observe the *conflict markers* ++ Change the file to your liking ++ Run `git add .` ++ Run `git merge --continue` + += Rebase