>_ IzzyLab

Hands-on task

This task is step 2 of the course “Git: first commits”

Your first commit

easy~6 min

The /root/recipes repository has already been created and has two recipe files, but no commits yet. Make the first commit, and include both files in it.

  • Commit author: name Alex Carter, email alex@example.com.
  • Commit message: First recipes (you can copy it from here).
What you'll practise:
  • git config
  • git add
  • git commit
  • index
  • commit author

Topic breakdown

A commit is a saved snapshot of the project's files with a signature: who made it, when and why (the message). The history is made of commits.

A commit takes two steps:

  1. git add file — put the file into the index (the staging area). The index is a draft of the future commit: whatever is in it gets saved.
  2. git commit -m 'message' — save the contents of the index as a new commit.

Why two steps: you can change many files and pick only some of them for the commit.

Git records an author — a name and an email — in every commit. You set them once with git config:

git config user.name 'Maria Lopez'
git config user.email maria@example.org

Without the --global flag the setting applies only to the current repository; with --global, to all of this user's repositories. To see what's configured: git config user.name.

Write the commit message so that a month later it's clear what changed: "Add a contacts page", not "fixes".

What's checked

  1. The repository has exactly one commit
  2. Both recipes made it into the commit
  3. The commit author is the one from the task
  4. The commit message is the one from the task

What it looks like