Step 1

Create a folder where you want to store the files for this chapter. I'm going to call this folder sleeptime-git.

Open the terminal, change the directory to sleeptime-git. (Alternatively, open this folder in VSCode and then open the integrated terminal.)

In the terminal, run the following command.

git init

Git is now ready to track all changes within the folder sleeptime-git. So, in Git jargon, we created a (local) repository inside the sleeptime-git folder.

A Git repository is a collection of files tracked by Git.

Create a new file README.md inside sleeptime-git folder. Next, run the following command in the terminal.

git status

You will get a list of untracked files.

The git status command displays the state of the Git repository.

Next, run the following command in the terminal.

git add README.md

Git now has taken a snapshot of the README.md. This process is like pressing command + c to make a copy in the memory (but the copy is not completed until you press command + v). (Please note that "copying" is not a great analogy because what is contained in a snapshot is mostly only the changes made to the file.)

In Git's jargon, we say changes in README.md are staged to be committed.

You can run git status now to see the state of your repository. The README.md must appear in green color under "changes to be committed."

Next, run the following command in the terminal.

git commit -m "Create README file"

Git now has saved (committed) the snapshot you've created earlier using the add command. This process is like pressing command + v (after having pressed command + c to make a copy). Commits are like versions of your repository where you can access at any future point. A commit is part of the history of your repository.

To see a log of your commits, you can run the following command in the terminal.

git log

On my computer, git log produced the following output:

commit f034c1ea747a6ab6726681d60a7bd5b097ff40b8 (HEAD -> master)
Author: Yinzhi Cao <yinzhi.cao@jhu.edu>
Date:   Sat Sep 5 10:21:54 2020 -0400

    Create README file

The command git log lists the commits made in reverse chronological order. Each commit has a commit ID (a hash identifier), the author's name and email, the date written, and the commit message.