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:
echo "Hello, Git!" > hello.txt2. Stage the file
Add the file to Git's staging area:
git add hello.txtTo add all files at once, use:
git add .3. Commit (save!)
Save the staged files with a descriptive message:
git commit -m "Add hello.txt file"4. Check your history
See your commit in the log:
git log --onelineYou 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 commitwithoutgit 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 changesgit commit -m "message"saves a snapshot- Use
git log --onelineto view commit history