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

Contents

  • This session
  • Learning objectives
    • Setup
    • First steps with Git
    • ๐Ÿš€ Optional: Git essentials
  • recipes project
  • Exercises
    • Configure Git
    • Initialize a Git repository
    • Add content and commit changes
  • ๐Ÿš€ Bonus exercises
    • Amend a commit
    • Create a .gitignore file
  • Slides
  • Cheatsheet
    • Setup
    • First steps with Git
    • Git essentials

Setup & First steps with Git

Session 03

Starts at:

10:45

Slides Chapter: Setup Chapter: First steps with Git Chapter: Git Essentials Survey: Git Basics

This session

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

  1. Reading: Read the chapters โ€œSetupโ€, โ€œFirst steps with Gitโ€ and, optional, โ€œGit Essentialsโ€ in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises for the recipes project.
  4. Quiz: Test your knowledge with the quiz.

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

Setup

๐Ÿ’ก You know how to set up Git for the first time
๐Ÿ’ก You have set up Git on your computer
๐Ÿ’ก You understand the difference between the three Git configuration levels
๐Ÿ’ก You know how to configure your username and email address in Git
๐Ÿ’ก You have set up your preferred text editor when working with Git
๐Ÿ’ก You can escape the command-line text editor Vim

First steps with Git

๐Ÿ’ก You can initialize a Git repository
๐Ÿ’ก You can stage and commit changes

๐Ÿš€ Optional: Git essentials

๐Ÿ’ก 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

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 recipe to the recipes repository.

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

Exercises

Configure Git

  1. If needed, navigate into the recipes folder using the command line.
  2. Set your Git username.
  3. Set your Git email address.
  4. Change the default name of the initial branch to main
  5. ๐Ÿš€ Optional: Change your default text editor.
  6. List the Git configuration settings.

Initialize a Git repository

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

Add content and commit changes

  1. Create a new file called recipes.txt.
  2. Add a short recipe to recipes.txt (any favorite or an intriguing AI-generated one).
  3. Stage the new recipes.txt file.
  4. Commit the changes in recipes.txt with a descriptive commit message.

๐Ÿš€ Optional: Commit at least three additional changes in recipes.txt.

๐Ÿš€ Bonus exercises

Amend a commit

  1. If needed, navigate into the recipes repository using cd recipes (or a similar path).
  2. Make additional changes to your recipes.txt file.
  3. Stage the changes.
  4. Amend the previous commit to include the new changes.
  5. Check the commit history to verify that the last commit message has not changed.

For example, add a recipe without a title first, commit, then add a title and amend the previous commit to add the title change to the same commit.

Create a .gitignore file

  1. If needed, navigate into the recipes repository using cd recipes (or a similar path).
  2. Add a random 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 the random file to the .gitignore 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: Let your repository ignore .DS_Store.

Slides

How 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.

Hereโ€™s what the Chrome print dialog would look like with these settings enabled:

Screenshot of Chrome print dialog with the first slide/page of 43 shown on the left, and print options on the right. The Destination print option has Save as PDF selected.

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

Cheatsheet

Setup

Command Description
git config Get an overview of Git config commands
git config --global "user.name" Sets Git username
git config --global "user.email" Sets Git email address
git config --global core.editor "editorname" Sets Git text editor
git config --global init.defaultBranch main Sets default branch name to main
git config --list Views set Git configurations

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

Git essentials

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
ยฉ 2024 Dr. Lennart Wittkuhn
 
License: CC BY 4.0