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

Contents

  • This session
  • Learning objectives
  • recipes project
    • First steps with Git
    • Git Essentials
  • Exercises
    • Initialize a Git repository
    • Add content and commit changes
    • Amend a commit
    • Create a .gitignore file
  • Slides
  • Cheatsheet
    • First steps with Git

Git Essentials

Session 4

Starts at:

11:00

Slides Chapter: First steps with Git Chapter: Git Essentials

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 can initialize a Git repository.
πŸ’‘ You can check the status of a Git repository.
πŸ’‘ You understand the difference between the staging area and a commit.
πŸ’‘ You can stage and commit changes.
πŸ’‘ You understand the difference between a commit message and a description.

πŸ’‘ You know what good commits look like.
πŸ’‘ You know how to explore the commit history.
πŸ’‘ You can compare different commits.
πŸ’‘ You know how to use and create a .gitignore file.
πŸ’‘ You can discuss which files can (not) be tracked well with Git and why.
πŸ’‘ You know how to track empty folders in Git repositories.

recipes project

First steps with Git

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

  1. You set up Git.
  2. You initialized your recipes folder as a Git repository.
  3. You committed your first file to the recipes repository.

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

Git Essentials

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

  1. Commit at least three changes in recipes.txt.
  2. Make at least one commit using git commit --amend.
    • For example, add a a new entry without a title first, commit, then add a title and use git commit --amend to add the title change to the same commit.
  3. Create a .gitignore file.
    • Everyone: Create a random file that you want to ignore, for example image.jpg.
    • All macOS users: Let your repository ignore .DS_Store.
  4. πŸš€ Optional: Commit .gitkeep in an otherwise empty directory.

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

Exercises

Initialize a Git repository

  1. If needed, navigate to the project folder using the command line.
  2. Initialize a new Git repository in the project folder.

Add content and commit changes

  1. Open recipes.txt (created in the command-line session) in a text editor.
  2. Add a short recipe entry (a title and a short list of ingredients β€” use any favorite or an intriguing AI-generated one).
  3. Stage the file.
  4. Commit the changes with a descriptive commit message.

πŸš€ Optional: Commit at least three additional recipe entries in recipes.txt.

Amend a commit

  1. If needed, navigate to the project repository using the command line.
  2. Add a new recipe to recipes.txt without a title, and commit the change.
  3. Now add a title to the recipe.
  4. Stage the change.
  5. Amend the previous commit to include the title change (without altering the commit message).
  6. Check the commit history to verify that the last commit message has not changed.

Create a .gitignore file

  1. If needed, navigate to the project repository using the command line.
  2. Add a file to your repository that you want to ignore, for example an image file like image.jpg.
  3. Check the state of your repository to confirm that Git noticed the added file.
  4. Create a .gitignore file.
  5. Add a pattern to the .gitignore file to ignore the file.
  6. Check the state of your repository again to confirm that Git now ignores the added file.
  7. Stage the changes in your repository.
  8. Commit the .gitignore file using a descriptive commit message.
  9. πŸš€ All macOS users: Also let your repository ignore .DS_Store.

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

First steps with Git

Command Description
git init Initializes a folder as a Git repository
git status Shows Git tracking status of files in the repository
git add Adds file(s) to the staging area
git commit Commits staged files
git commit -m "commit message" Commits staged files with a commit message
Command Description
git log Views past commits
git diff Views made changes compared to the last commit
git mv Renames or moves files and automatically stages the changes

Β© 2026 Dr. Lennart Wittkuhn

 

License: CC BY 4.0