Next.js Fullstack Training
Chapter 4
Git Cheat Sheet
4.1 Commands You'll Use Every Day
| Command | What it does | When to use it |
|---|---|---|
| git status | Shows what files changed | Before every commit |
| git pull | Download latest from GitHub | Every morning |
| git checkout -b name/type/desc | Create a new feature branch | Starting any new task |
| git add . | Stage all changes | Before committing |
| git commit -m "type: message" | Save with a message | Every working state |
| git push | Upload to GitHub | After committing, end of day |
| git rebase main | Pull in latest main changes | When main has new commits |
| git stash | Temporarily hide changes | When switching branches urgently |
| git log --oneline | See recent commit history | Debugging, orientation |
4.2 Conventional Commits Format
Format: type(scope): short description feat(tasks): add drag-and-drop between lists fix(auth): redirect to /login when session expires chore(deps): upgrade drizzle to v2.1.0 "fixed stuff" / "WIP" / "update"
| Type | When to use |
|---|---|
| feat | A new feature visible to the user |
| fix | A bug fix |
| chore | Tooling, deps, config — nothing the user sees |
| refactor | Code restructured without changing behaviour |
| test | Adding or fixing tests |
| docs | Documentation only |
4.3 Day-to-Day Git Flow (Capstone)
Because you work on your own fork, there is no shared branch to protect. Keep it simple:
- git checkout main && git pull (sync with upstream if mentor pushed updates)
- Write code. Commit often with Conventional Commits format.
- git push (push to your fork main at end of each session)
Pro Tip
Feature branches are optional for the capstone — use them when working on something risky you might want to discard.
For project submissions (Foundations 1 & 2), you will share your repo URL directly with your mentor for review.
The only formal code review in this program happens on those two project submissions.
4.4 Fixing Common Mistakes
| Situation | Fix |
|---|---|
| Committed to main by mistake | git checkout -b rescue/my-changes then git checkout main && git reset --hard origin/main |
| Undo last commit (keep changes) | git reset --soft HEAD~1 |
| Undo last commit (discard changes) | git reset --hard HEAD~1 permanent |
| Rebase conflict | Remove <<<< ==== >>>> markers. Keep correct code. git add . && git rebase --continue |
| Accidentally deleted a file | git checkout HEAD -- path/to/file.tsx |
Common Mistake
NEVER run git push --force on main or a shared branch.
NEVER commit .env files. Add .env* to .gitignore immediately.
Accidentally committed a secret? Tell your mentor NOW. The key must be rotated.