GitNoon Lesson 2

Get Ready for Lesson 2!

  1. Login to your account on github.com
  2. If you missed the previous lesson, ask for help with the quick-setup on the next slide

Quick Setup

  1. Configuring Git:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global core.editor nano
git config --global init.defaultBranch main
# For Linux or macOS:
git config --global core.autocrlf input
# For Windows:
git config --global core.autocrlf true
# If you're behind a corporate proxy on Windows
git config --global http.sslBackend schannel
  1. Setting up a blog repository:
mkdir blog
cd blog
git init
echo "# Entry 1" > entry_1.md
git add entry_1.md
git commit -m "Add first blog entry"
git status

Thanks

  • To the host for the great venue!
  • To our sponsors

Administrivia

  • Fire escapes
  • Toilets
  • Cleaning up after ourselves
  • WiFi

Lunch Talk: Exploring History

  • Getting value from the time you spend crafting clean commits and helpful commit messages
  • Our key tools:
    • git log
    • git blame
    • git bisect
  • The power of plain text

Answering Questions with git log

  • We’ve already used git log to list commits
  • git log can be customised with options
  • git log --help lists the available options
    • Hold arrow keys to scroll up and down

What has Guido worked on lately?

git log --stat --author "Guido"

--stat counts lines changed in each file

What is the history of our README?

git log --stat --follow -- README.rst

  • --follow includes commits made when the file had another name (Git can follow most renames)
  • The -- tells Git that what comes next is a file

How was issue 123458 fixed?

git log --grep "gh-123458:"

  • --grep searches commit messages - so make them useful!
    • Follow project conventions (like including issue numbers)
    • Include keywords relating to your work

When was parse_entry removed?

git log --patch -S "parse_entry"

  • -S searches the contents of lines changed
    • Known as the Git Pickaxe
  • --patch shows the diff of each commit

Combine options for more power!

Answer very specific questions like:

Didn’t Ben make an important change to login.html the week before we went on holiday?

git log \
    --author Ben \
    --since 2023-12-18 \
    --until 2023-12-22 \
    -- login.html

Who wrote this?

git blame -- README.rst

  • For each line, find out: who, when, and which commit
  • Use git show 914476 to see the contents of a commit
  • Ignore whitespace changes with -w
  • Follow copy-pasting within the file (-M) or whole repo (-C)

When did this break?

  • git bisect start bad1 g00d
    • Git “checks out” commit halfway between for you to inspect
  • git bisect good
  • git bisect bad
  • git bisect bad
  • To clean up:
    git bisect reset
  • If you can’t test a commit:
    git bisect skip
  • You can even supply a test script!

The Power of Plain Text

  • We’ve seen compelling reasons to track your projects with Git
    • And why to write small, self-contained commits with good messages!
  • Like many “Unix” tools, Git is especially good for plain text
    • git diff, git blame, Git pickaxe, etc.
  • E.g. Markdown for formatted text as readable plain text:

Plain Text Tools

Tutorial Objectives

  1. Configuring your GitHub account to support SSH authentication
  2. Sharing repos on GitHub
  3. Updating remote and local repos
  4. Instructing Git to ignore certain files
  5. Publishing a repo as a website on GitHub

Homework

  1. History exploration exercises
    • Clone the “awesome lists” repo: github.com/sindresorhus/awesome
    • Use Git to answer the following questions:
      1. Who was the last person to edit the license and why?
      2. When was “ChatGPT” added to the list?
      3. Find all commits with the message “Meta tweaks”
      4. What was the first commit by user RichardLitt?
  2. Continue your daily blog entries