Initialize a local Git repository

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

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

git init

In the terminal, run the following command.

git init -b main

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

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

git status

Create a new file README.md inside better-sleeptime 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.

git add

Next, run the following command in the terminal.

git add README.md

Git now has taken a snapshot of the README.md. This is like pressing command + c to make a copy in the memory (but the copy is not completed until you press command + v). Copy is not a great analogy because what is contained in a snapshot is mostly only the changes made to the file (the differences from one version to another instead of a complete copy).

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 our repository. The README.md must appear in green color under "changes to be committed".

git commit

Next, run the following command in the terminal.

git commit -m "Add README file"

Git now has saved (committed) the snapshot you've created earlier using the add command. This 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.

git log

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 3d7292fd9530ce727fcf8323a4b2cc207d1e6ad5
Author: Ali Madooei <alimadooei@gmail.com>
Date:   Thu Sep 1 09:47:33 2022 -0400

    Add 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.

The .git folder

You may be wondering where does git store the history of of your repository among other information. Well, Git has created a hidden .git folder inside the better-sleeptime directory.

You can enable viewing hidden files and folders in your operating system to view this folder with its content.

You should never manually modify the .git folder. Moreover, you can remove the local Git repository by delete the .git folder.