You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Commits are the building blocks of Git history. Each commit is a permanent snapshot of your project at a specific moment. In this lesson you will learn how to move changes from your working directory through the staging area and into a commit, and how to write commit messages that communicate clearly.
The staging area (also called the index) is what makes Git flexible. Instead of committing every changed file at once, you explicitly choose which changes to include in the next commit. This lets you craft clean, focused commits even when you have unrelated edits in progress.
Use git add to stage changes:
# Stage a single file
git add README.md
# Stage multiple files
git add index.html style.css
# Stage all changes in the current directory
git add .
After staging, run git status to confirm:
git status
Staged files appear under Changes to be committed in green.
Once your changes are staged, create a commit:
git commit -m "Add README with project overview"
The -m flag lets you provide the commit message inline. Git records the snapshot along with your name, email, the timestamp, and a unique identifier called a SHA (a 40-character hexadecimal hash).
A good commit message explains why the change was made, not just what changed. Follow these conventions:
git commit -m "Fix null pointer error in user login flow
The login handler did not check whether the session token
existed before accessing its properties. This caused a crash
on first load if no session cookie was present."
For tracked files (files Git already knows about), you can stage and commit in one step with -a:
git commit -am "Update homepage copy"
This does not add brand-new untracked files — only changes to already-tracked files.
Before committing, see exactly what is staged:
# Difference between working directory and staging area
git diff
# Difference between staging area and last commit
git diff --staged
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.