Your First Repository: Staging & Commits
1 min read
Create a repository
mkdir my-app && cd my-app
git init
git init creates a hidden .git folder — that is your repository. Everything Git knows lives there.
The commit workflow
Saving work in Git is two steps, not one:
- Stage the changes you want to save (
git add) - Commit them into history (
git commit)
echo "# My App" > README.md
git status # see untracked/changed files
git add README.md # stage this file
git commit -m "Add project README"
Why two steps?
Staging lets you craft a clean, logical commit. Say you fixed a bug and changed some docs. You can stage and commit them separately so history stays meaningful:
git add src/login.js
git commit -m "Fix login validation bug"
git add README.md
git commit -m "Update setup instructions"
Writing good commit messages
A good message explains why, not just what:
- ❌
git commit -m "changes" - ✅
git commit -m "Fix crash when email field is empty"
Seeing history
git log --oneline # compact history
Each line is one snapshot, identified by a unique hash like a1b2c3d.