Git Cheat Sheet, Tips & Portfolio Capstone
Lesson opener
In one line: One-page command cheat sheet (print or bookmark).
Why it matters: This shows up at work when you need to one-page command cheat sheet (print or bookmark).
Before this lesson: CI/CD & deployment
Before you start
| Resource | Link |
|---|---|
| Previous | CI/CD & deployment |
| Next | Courses |
| Time | ~45 minutes (+ capstone project) |
What you will learn
- One-page command cheat sheet (print or bookmark)
- Tips & tricks professionals use daily
- Future-ready topics: signed commits, monorepos, AI-assisted Git
- Capstone: publish a portfolio repo the right way
Section 1 — Daily command cheat sheet
Setup (once)
| Command | Purpose |
|---|---|
git config --global user.name "Name" | Commit author |
git config --global user.email "email" | Commit email |
git config --global init.defaultBranch main | Default branch name |
Every session
| Command | Purpose |
|---|---|
git status | What changed? |
git diff | Line-by-line unstaged diff |
git add file / git add . | Stage changes |
git commit -m "msg" | Save snapshot |
git log --oneline -10 | Recent history |
git pull | Get remote changes |
git push | Send commits upstream |
Branches
| Command | Purpose |
|---|---|
git switch -c name | Create + switch branch |
git switch main | Back to main |
git merge branch | Merge into current branch |
git branch -d name | Delete merged branch |
Undo (safe first)
| Command | Purpose |
|---|---|
git restore file | Discard unstaged edits |
git restore --staged file | Unstage |
git stash / git stash pop | Park WIP |
git revert SHA | Undo commit on shared branch |
Remote
| Command | Purpose |
|---|---|
git clone URL | Copy repo |
git remote -v | List remotes |
git fetch | Download without merge |
git push -u origin main | First push sets upstream |
Section 2 — Tips & tricks
Aliases (save typing)
git config --global alias.st status
git config --global alias.co switch
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all -20"See who broke the line
git blame README.mdPretty log
git log --oneline --graph --decorate --allDiscard everything local (danger — read twice)
git fetch origin
git reset --hard origin/mainOnly on your feature machine when you want to match remote exactly.
Partial stage (advanced)
git add -pStage hunks interactively — great for splitting one file into two commits.
Section 3 — Future-ready (2026+)
| Topic | Why it matters |
|---|---|
| Signed commits (SSH or GPG) | Proves commit authorship — required on some enterprise repos |
| Monorepos | One repo, many apps (Google-style) — tools: Nx, Turborepo |
| Trunk-based development | Short-lived branches, frequent merges to main |
| AI in Git workflow | Cursor/Copilot suggest commits & PR descriptions — you still review |
| GitHub Copilot code review | Automated first pass on PRs — not a substitute for human review |
| OIDC in Actions | Cloud deploy without long-lived cloud keys |
| Git LFS | Large files (video, datasets) — pointer in Git, blob elsewhere |
Enable signed commits (SSH):
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign trueSection 4 — What never to commit
| Item | Why |
|---|---|
.env, API keys | Secret scanning + theft |
node_modules/, .venv/ | Rebuilt from lockfiles |
| Personal data (GDPR) | Legal liability |
| Huge binaries | Use LFS or external storage |
| Generated build output | CI builds fresh |
Use gitignore templates.
Section 5 — Capstone: portfolio repo
Full “what belongs in a portfolio” (including a no-Git path for Excel/SQL-first learners): Building your portfolio.
Build one public repo showcasing your learning:
my-data-portfolio/
├── README.md # Screenshots + links
├── .gitignore
├── .github/workflows/ci.yml
├── notebooks/ # Python analysis
├── sql/ # Sample queries
├── LICENSE
└── CONTRIBUTING.mdRequirements:
- At least 10 meaningful commits (not one giant dump)
- README with setup instructions
- One merged PR (even solo — practice the flow)
- CI workflow that runs at least one check
- No secrets in history
Link it on LinkedIn — recruiters clone repos, they don't read ZIP attachments.
Section 6 — Troubleshooting quick fixes
| Problem | Fix |
|---|---|
Permission denied (publickey) | Add SSH key to GitHub |
rejected — non-fast-forward | git pull then push |
merge conflict | Edit files, git add, commit |
detached HEAD | git switch main |
| Wrong branch committed | git switch -c rescue then cherry-pick or reset (see git3) |
| Committed to wrong branch | git switch correct-branch then git cherry-pick SHA |
Section 7 — Full workflow diagram
Checklist
Teacher walkthrough: personal cheat sheet that is yours
All figures illustrative.
Step 1 — Collect commands you actually used in git1–git7 (not every flag on earth).
Step 2 — Group by job. Daily, undo, branch/PR, remote, CI.
Step 3 — Add one failure note per group (what went wrong once).
Step 4 — Acceptance. Peer can follow your sheet to init → commit → push → PR.
Failure example: scraped mega cheat sheet never practised
Symptom: In an interview, blank on status vs log.
Diagnosis: Collection without use.
Correction: Capstone sheet = commands you ran this course + your own wording.
Validation: Recreate first-repo flow from your sheet only.
Guided practice
Which three commands belong in a "panic" section?
Complete solution: git status, git log --oneline, and a safe undo (restore / revert) — not reset --hard.
Independent practice
Acceptance criteria:
- Cheat sheet covers init→commit→branch→PR→undo.
- One CI/deploy note.
- No secrets pasted.
- Self-check: perform the flow using only your sheet.
Capstone acceptance criteria
- [ ] Sheet is personalised (not a raw dump of the internet).
- [ ] Includes safe undo guidance.
- [ ] Includes Git vs GitHub clarification.
- [ ] Peer/self review signed.
Common mistakes
- Documenting force-push as normal.
- Omitting
.gitignore. - No PR/test-plan reminder.
What's next
Android ecosystem — you'll use Git for every mobile lesson and Play Store build.
Or revisit Setup: Git shortcut as a quick reference anytime.