The Complete Git Workflow
Now that you know the fundamental commands, let's see how they fit together into a daily workflow. This is the cycle you'll repeat hundreds of times as a developer.
The Core Loop
Every change you make in Git follows this pattern:
Edit --> Status --> Add --> Commit
^ |
| |
+----------------------------------+
- Edit your files in your editor
- Status — run
git statusto see what changed - Add — stage the changes you want with
git add - Commit — save a snapshot with
git commit - Repeat
A Typical Session
Here's what a real workflow looks like:
# 1. Check where you are
git status
# 2. Make your changes
# (edit files in your editor)
# 3. Review what changed
git diff
# 4. Stage specific files
git add src/feature.js
git add src/feature.test.js
# 5. Double-check what's staged
git diff --staged
# 6. Commit with a clear message
git commit -m "Add user profile feature"
# 7. Verify in the log
git log --oneline -3
Choosing What to Commit
Not every change needs to go into the same commit. Good practice is to make small, focused commits that each do one thing:
- One bug fix = one commit
- One feature = one commit (or a small series)
- Refactoring = separate commit from behavior changes
Use git add selectively to stage only the files relevant to each commit.
The Mental Model
Think of your Git workflow as three areas:
| Area | What lives there | Command to move forward |
|---|---|---|
| Working directory | Your current edits | git add |
| Staging area | Changes ready to commit | git commit |
| Repository | Permanent history | git log to view |
Files flow from left to right. You control exactly what moves forward at each step.
Quick Reference
| Command | Purpose |
|---|---|
git status | See what has changed |
git diff | See unstaged changes in detail |
git add <file> | Stage a file for commit |
git diff --staged | See staged changes in detail |
git commit -m "msg" | Save a snapshot |
git log --oneline | View recent history |
git commit --amend | Fix the last commit |
What's Next?
With these basics mastered, you're ready to learn about branching — Git's killer feature that lets you work on multiple things at once without them interfering with each other.