Session 4: Basic Git workflow

Track, organize and share your work: An introduction to Git for psychological research

Course at University of Hamburg

Slides | Source

License: CC BY 4.0 DOI

April 29 2024 (12:15 pm)

1 Admin

How can I download the slides as PDF?

Instructions can now be found above the slides on the course website:

How can I download the slides as PDF?

To print 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.

When do I have to “Take the quiz”?

  • Many chapters contain a “Take the quiz!” button
  • These are the same quizzes that we assign to your as part of the sessions’ learning objectives
  • TL;DR: Take the quiz when we tell you

lennartwittkuhn.com/version-control-book/chapters/first-steps-git.html

Will we also learn about Python or R?

  • No, not directly, but you are free to use Git to track Python or R files that you use for other projects
  • We will have a Quarto workshop in two weeks:

More questions from last week

“Where can I find an overview of all the commands we learned about?”

See the Cheatsheet section at the end of each chapter in the Version Control Book.

“How can I enable copy-paste in Git Bash?”

  1. Click on the Git Bash icon in the top-left corner.
  2. Choose Options.
  3. Go to Keys menu.
  4. Enable Copy and Paste (Ctrl/Shift + Ins) option.
  5. Click Apply and Save.

“How do I find the Users folder on Windows?”

  • Use ~
  • If pwd is at /: you can still use cd C:

“What should my recipes folder look like?”

At least, a folder with recipes.txt inside with at least one commit.

2 Last week: Setup and first steps with Git

Schedule

No Date Title Contents Reading Survey/Quiz
1 2024-04-08 Introduction to version control Organisational matters
Overview of seminar sessions
Introduction to version control
Introduction to Git and its advantages
Intro to version control Course introduction Survey
2 2024-04-15 Command line File Systems
Benefits of the Command Line
Basic Command Line commands
Command Line Command Line Quiz
3 2024-04-22 Setup + Git Fundamentals Installation and configuration of Git
Initializing a Git repository
Basic Git commands
Installation, Setup, First steps with Git Installation Survey, Git Basics Quiz
4 2024-04-29 Basic Git workflow Practicing basic Git commands
Ignoring files with .gitignore
Good commit messages
First steps with Git Git Basics Quiz
5 2024-05-06 Git Branching and Merging Understanding branches in Git
Creating and switching between branches
Merging branches
Resolving merge conflicts
Branches Git Branches Quiz
6 2024-05-13 Quarto Workshop Introduction to Quarto
7 2024-05-20 Whit Monday Cancelled
8 2024-05-27 Introduction to GitHub Introduction to remote repositories
Creating a GitHub account
Creating and managing repositories on GitHub
Pushing and pulling changes
GitHub Intro GitHub Quiz
9 2024-06-03 GitHub with collaborators Cloning a remote repository
Branching and merging in a collaborative environment
Pull Requests
GitHub Issues
Graphical User Interfaces (GUIs), e.g., GitKraken
GitHub Intro, GitHub Issues GitHub Quiz
10 2024-06-10 GitHub with the world Forking a remote repository
README files
Project Management
GitHub Intro, GitHub Issues GitHub Quiz
11 2024-06-17 Repetition and Practice Repetition and Practice
12 2024-06-24 Publishing Creating Tags with Git
Creating Releases with GitHub
Using Zenodo for scientific publishing
Licences
Citation Files
Tags and Releases
13 2024-07-01 Graphical User Interfaces (cancelled) Repetition and Practice
Introduction to using GUIs
Graphical User Interfaces
14 2024-07-08 Summary & Wrap-Up Course evaluation
Repetition and Practice
Introduction to using GUIs
Graphical User Interfaces

Last week: Setup and first steps with Git

lennartwittkuhn.com/version-control-book/chapters/first-steps-git.html

Last and this week’s 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
💡 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

Note: These are the learning objectives for this and next week.

Staging and Committing

Staging:

  • Command: git add
  • Purpose: Preparing and organizing files before they are recorded in the repository’s history.

Committing:

  • Command: git commit -m "commit message"
  • Purpose: Saving the changes in the staged files to the repository’s history, creating a snapshot.

Source: git-scm.com

git log

git log

e.g:


commit 3f6db14ed93d6e92a207a9a3ac5f8b8c5c5c5c34 (HEAD -> main, origin/master, origin/HEAD)
Author: Jane Doe <jane@example.com>
Date:   Tue Apr 24 14:24:48 2024 -0700

    Fix the widget rendering issue in the dashboard

commit a4324f44d3e85723a4d91cb9e07132b7115e4941
Author: John Smith <john@example.com>
Date:   Mon Apr 23 16:17:59 2024 -0700

    Update dependencies to newer versions

commit fa204b9145bf7fc7ff226a26b49a567fc2eb1b94
Author: Alice Johnson <alice@example.com>
Date:   Sun Apr 22 15:08:43 2024 -0700

    Initial commit of project files

commit b9690b287bdfec6e17af39b7337b84e9ebf6f046
Author: Lennart Wittkuhn <lennart.wittkuhn@tutanota.com>
Date:   Fri Mar 22 15:19:43 2024 +0100

    move illustration of bad git commits (xkcd comic) and edit sentence

commit d8d770dd84cd19086f41d8d38752b223c8130859
Author: konradpa <konrad@pagenstedt.de>
Date:   Wed Mar 6 13:51:13 2024 +0100

    add image to setup chapter

commit 074c9f6e12dd5fc8cc61de9f31efbdbce41a7583
Author: konradpa <konrad@pagenstedt.de>
Date:   Wed Mar 6 13:51:07 2024 +0100

    add image to rewriting history chapter

Terminology: What are “branches”?

See next week!

lennartwittkuhn.com/version-control-book/chapters/branches.html

Terminology: What is HEAD?

lennartwittkuhn.com/version-control-book/chapters/first-steps-git.html#head

3 Live demonstrations

4 This week

Today’s chapter

lennartwittkuhn.com/version-control-book/chapters/first-steps-git.html

Your turn

  1. Content Review: Read the chapter “First steps with Git” in the Version Control Book. Start at “Logging commits”
  2. Implementation: Try out the commands in the chapter! Play around! Have fun!
  3. Exercises: Complete the implementation exercises (see below).
  4. Quiz: Complete the online quiz.

Implementation Exercises

  1. Commit at least three changes in recipes.txt.
  2. Make at least one commit using git commit --amend.
    • For example, add a recipe 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 random-file.docx.
    • All macOS users: Let your repository ignore .DS_Store
  4. 🚀 Optional: Commit .gitkeep in an otherwise empty directory

Ask questions!

Let’s git started!