Basics of Commits

INPUT · Slides

Your first commit

01 / 10

Git is a tool for safe rollbacks

Have you ever been editing a file and thought:

"The previous version was better, but I already saved over it."

You could keep multiplying files — report_final.txt, report_final2.txt, report_really_final.txt — but you soon lose track of which was which.

Git turns that version tracking and saving into a professional tool. You can safely roll back to any commit whenever needed, and the exact changes, timestamps, and reasons are preserved as messages.

02 / 10

What is running on this screen

In this course, you use a Git environment running directly inside your browser/device. No code is sent to an external server.

There are always three areas on screen:

  • Working tree … the files you are currently editing
  • Local repository … the history saved as commits
  • Console … output and responses from git commands

To edit a file, tap its name in the file list. Editing files is the role of your editor, not git, which is why file editing is kept separate from git commands.

03 / 10

Moving through three areas

With Git, your changes move sequentially through three areas. This is the fundamental mental model:

  • Working tree … the actual files you are editing right now
  • Staging area (index) … where you register changes to be included in the next commit
  • Local repository … permanently recorded commit history

Why have a staging area in the middle? Because you might not want to commit every edited file at once. It allows you to selectively stage two out of three modified files.

04 / 10

git init — Initialize a repository

First, put your current directory under Git version control. Running git init creates a Git repository to store commit history.

You only need to run it once when starting a project. Running it again in an existing repository won't break anything, but normally it is only executed once at setup.

$ git initInitialized empty Git repository

05 / 10

git status — Check current status

When in doubt, run git status. This is the single most valuable command in Git.

It displays your current branch, staged files, modified files, and untracked files. Running it never breaks anything, so check it frequently.

Untracked files refers to files that have never been tracked by Git. Git never commits files automatically, so new files remain here until you explicitly stage them.

$ git statusOn branch mainUntracked files:	memo.txt

06 / 10

git add — Add changes to the staging area

Register files you want to include in the next commit using git add.

You can specify individual files like git add memo.txt, or run git add . to stage all modified and new files in the current working directory at once. The . represents the entire current directory.

When git add succeeds, git outputs nothing. Remaining quiet upon success is standard Unix/Linux command behavior, not an error. Check with git status to verify.

$ git add memo.txt$ git statusOn branch mainChanges to be committed:	new file:   memo.txt

07 / 10

git commit — Record changes to repository

Permanently record staged changes to the repository history using git commit. Supply a commit message after the -m flag.

Each saved snapshot is called a commit. Git assigns each commit a unique hash (such as a1b2c3d) so you can reference or revert to it later.

The commit message is communication with your future self and teammates. A series of commits that all say update makes it impossible to know what changed. Always write brief, meaningful descriptions.

$ git commit -m "create shopping list"[main 9f2a1c4] create shopping list 1 file(s) changed

08 / 10

git log — View commit history

Once commits are recorded, inspect them with git log. Adding --oneline displays a concise one-line summary per commit.

The latest commit appears at the top. The short string on the left is the commit hash.

$ git log --oneline9f2a1c4 add milk3b7e5d1 create shopping list

09 / 10

The same 3 steps for editing files

Once a file is tracked, modifying it follows the exact same 3 steps:

1. Edit the file
2. Run git add to stage the changes
3. Run git commit -m "..." to record the commit

Remember: editing a file alone never adds it to a commit. Running git status will show Changes not staged for commit. Keep in mind that Git never commits changes automatically.

10 / 10

Hands-on practice

Now it's your turn to type commands.

You can tap the sample buttons below the console to insert commands, and edit them before pressing Enter.

Evaluation checks the resulting state of the repository. Whether you use git add . or git add memo.txt, your solution passes as long as the end state matches requirements.