Advanced git

Block 1.1: Reviewing git Basics

Jan Simson

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

What is git?

  • Version Control System (VCS)
    • Looks at the changes in your files
    • Records all changes over time to give you a full history
    • Similar to “track changes” in Microsoft Word / LibreOffice

Git only looks at and tracks the changes in a file

What is git? Strengths & Weaknesses

  • Strengths 💪
    • Very hard to lose files with git
    • Great for collaboration
    • Fast (like, really fast)
    • History allows you to go back and understand changes or revert when there are problems
    • Reproducibility

What is git? Strengths & Weaknesses

  • Weaknesses 😢
    • Can be a bit complicated to use (esp. at first)
    • History takes up file space (but only little)
    • Struggles with binary (i.e. non-text) files
    • Struggles with large files
      • Not good for storing data!
    • You do need to explicitly use it i.e. it doesn’t just work in the background

CLI vs. GUI: git

*: These programs have a different main purpose, but also offer the option of using git via their GUI.

git commands

I hope some of these git commands sound familiar to you.

  • git status
  • git init
  • git add
  • git commit
  • git restore
  • git stash
  • git checkout
  • git branch
  • git switch
  • git merge
  • git pull / push
  • git cherry-pick

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)

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

Demo: Tracking Changes in VSCode

Since VSCode is primarily a text editor, git functionality is hidden in the sidebar

  • Demo: Default git features in VSCode
  • Demo: Advanced features via gitLens

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

End of Section 🎉

Any Questions?

[🏡 Back to Overview]

[⏩️ Next Section]