Advanced git

Block 1.1: Reviewing git Basics

Jan Simson

Background: https://unsplash.com/photos/842ofHC6MaI

The Classic Git Flow

The 3 Levels of Changes in git

Changes can be either unstaged, staged or commited.

  • When we first make a change it is unstaged
  • Once we add the change to the staging area it is staged
  • We can then commit all staged changes

The 3 Levels of Changes in git

Changes can be either unstaged, staged or commited.

  • We can restore the commited version (and remove any unstaged changes)

A small addendum: git add -i

You can also interactively add changes with -i.

git add -i
#            staged     unstaged path
#   1:    unchanged        +4/-0 1.1-git-basics.qmd

# *** Commands ***
#   1: status       2: update       3: revert       4: add untracked
#   5: patch        6: diff         7: quit         8: help
# What now> 

There’s also an extension available.

Practical: Cookbook (1)

  1. Create a new directory called git-example
  2. Initialize a git repository in the new directory
  3. Create a new file cookbook.md in your git-example directory
  4. Search for your favorite recipe online and copy the title into the file
    • Tip: Use english language recipes
  5. Commit the changes
  6. Add the ingredients into the file and commit them, too

Practical: Cookbook (2)

  1. Add the cooking steps into the file and commit them
  2. Delete the cookbook.md and restore it
  3. Explore the repo status & history
  4. Add a second recipe step by step

Expanding on .gitgnore

  • Old news: You can ignore files by adding them to .gitignore 📰
  • Maybe new: You can reverse ignored files with a !
    • e.g. dir/** and !dir/.gitkeep
  • Ignoring a directory: dir/ vs. dir/**
    • Q: What will happen with dir/ and !dir/.gitkeep?
  • ❗️ With dir/, the whole directory is ignored and git will not scan it at all

End of Section 🎉

Any Questions?

[🏡 Back to Overview]

[⏩️ Next Section]