Back to Learning Path

Step 5: Add & Commit

Now that you have a repository, it's time to save your work. In Git, saving happens in two steps: add (stage your changes) then commit (save them permanently).


The Two-Step Save Process

Step 1: git add

Tells Git which files you want to include in your next save. Think of it as putting items in a shopping cart before checkout.

Step 2: git commit

Actually saves a snapshot of those files. Each commit is a permanent save point with a message describing what changed.


Let's Try It

1. Create a file

If you don't have one yet, create a simple file:

bash
echo "Hello, Git!" > hello.txt

2. Stage the file

Add the file to Git's staging area:

bash
git add hello.txt

To add all files at once, use:

bash
git add .

3. Commit (save!)

Save the staged files with a descriptive message:

bash
git commit -m "Add hello.txt file"

4. Check your history

See your commit in the log:

bash
git log --oneline

You should see your commit with the message you wrote. You just created your first save point!

Good Commit Messages

Write clear messages that describe what you changed:

"Add login page"

"Fix broken nav link"

"stuff" — too vague!

Common Mistakes

  • Forgetting to add before committing — If you just run git commit without git add, nothing gets saved.
  • Missing the -m flag — If you forget -m, Git opens a text editor. Just close it and try again with the flag.

Quick Summary

  • git add . stages all changes
  • git commit -m "message" saves a snapshot
  • Use git log --oneline to view commit history