• Home
  • About
  • Schedule
  • Sessions
  • Exercises
  • Code of Conduct

Contents

  • This session
  • Learning objectives
  • recipes project
  • Exercises
    • Branches
  • πŸš€ Bonus exercises
    • Create and resolve a merge conflict
  • Slides
  • Cheatsheet

Branches

Session 5

Starts at:

12:00

Slides Chapter: Branches

This session

In this session, you will work on the following tasks:

  1. Reading: Read the chapter(s) ?meta:chapter in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises for the recipes project.

As always:

  1. Try out the commands of this session and play around with them.
  2. Check whether you have achieved the learning objectives.
  3. Ask questions!
  4. Let’s git started!

Learning objectives

At the end of this session, you should have achieved the following learning objectives:

πŸ’‘ You understand the purpose and benefits of using branches in Git.
πŸ’‘ You can create and switch between branches.
πŸ’‘ You can merge branches and resolve merge conflicts.
πŸ’‘ You can name at least three best practices when working with branches.

recipes project

At the end of this session, you should have accomplished the following:

  1. You created a new branch and merged changes into your default branch (main or master).
  2. You created and resolved a merge conflict.

Please keep the recipes folder! We will continue to use it in the following sessions.

Exercises

Branches

  1. If needed, navigate to the project repository using the command line.
  2. Create a new branch with a descriptive name, e.g., add-pizza-recipe.
  3. Switch to the new branch.
  4. Add a new recipe to recipes.txt.
  5. Stage and commit the changes to recipes.txt on the new branch.
  6. View the contents of recipes.txt to verify your changes.
  7. Switch back to the default branch (main or master).
  8. View the contents of recipes.txt again to confirm that the changes do not exist on the default branch.
  9. Merge the new branch into your default branch.
  10. Delete the feature branch.
  11. View the contents of recipes.txt yet again to confirm that the changes have been merged into the default branch.

πŸš€ Bonus exercises

Create and resolve a merge conflict

  1. Deliberately create a merge conflict by making conflicting changes to the same section of recipes.txt on two separate branches (for example, change the same ingredient differently on each branch) and attempting to merge them. An example can be found in the branches chapter.
  2. Resolve the merge conflict.
  3. Delete the merged branch afterwards.

Slides

NoteHow can I download the slides as a PDF file?

To export the slides to PDF, do the following:

  1. Toggle into Print View using the E key (or using the Navigation Menu).
  2. Open the in-browser print dialog (CTRL/CMD+P).
  3. Change the Destination setting to Save as PDF.
  4. Change the Layout to Landscape.
  5. Change the Margins to None.
  6. Enable the Background graphics option.
  7. Click Save.

Note: This feature has been confirmed to work in Google Chrome, Chromium as well as in Firefox.

These instructions were copied from the Quarto documentation (MIT License) and slightly modified.

Cheatsheet

Command Description
git branch Lists / creates and deletes branches
git branch feature Creates the feature branch
git branch -d feature Deletes the feature branch
git switch Switches between branches
git switch feature Switches to the feature branch
git checkout Switches between branches
git checkout -b feature Creates and switches to the feature branch
git merge Merges branches
git merge feature Merges the feature branch into the current branch
git merge --abort Aborts a merge
git merge --squash Squaches commits on branch into a single commit and merge

Β© 2026 Dr. Lennart Wittkuhn

 

License: CC BY 4.0