Rana Maninder Singh
Lesson 8 of 8Git & GitHub

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

ResourceLink
PreviousCI/CD & deployment
NextCourses
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)

CommandPurpose
git config --global user.name "Name"Commit author
git config --global user.email "email"Commit email
git config --global init.defaultBranch mainDefault branch name

Every session

CommandPurpose
git statusWhat changed?
git diffLine-by-line unstaged diff
git add file / git add .Stage changes
git commit -m "msg"Save snapshot
git log --oneline -10Recent history
git pullGet remote changes
git pushSend commits upstream

Branches

CommandPurpose
git switch -c nameCreate + switch branch
git switch mainBack to main
git merge branchMerge into current branch
git branch -d nameDelete merged branch

Undo (safe first)

CommandPurpose
git restore fileDiscard unstaged edits
git restore --staged fileUnstage
git stash / git stash popPark WIP
git revert SHAUndo commit on shared branch

Remote

CommandPurpose
git clone URLCopy repo
git remote -vList remotes
git fetchDownload without merge
git push -u origin mainFirst 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.md

Pretty log

git log --oneline --graph --decorate --all

Discard everything local (danger — read twice)

git fetch origin
git reset --hard origin/main

Only on your feature machine when you want to match remote exactly.

Partial stage (advanced)

git add -p

Stage hunks interactively — great for splitting one file into two commits.


Section 3 — Future-ready (2026+)

TopicWhy it matters
Signed commits (SSH or GPG)Proves commit authorship — required on some enterprise repos
MonoreposOne repo, many apps (Google-style) — tools: Nx, Turborepo
Trunk-based developmentShort-lived branches, frequent merges to main
AI in Git workflowCursor/Copilot suggest commits & PR descriptions — you still review
GitHub Copilot code reviewAutomated first pass on PRs — not a substitute for human review
OIDC in ActionsCloud deploy without long-lived cloud keys
Git LFSLarge 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 true

Section 4 — What never to commit

ItemWhy
.env, API keysSecret scanning + theft
node_modules/, .venv/Rebuilt from lockfiles
Personal data (GDPR)Legal liability
Huge binariesUse LFS or external storage
Generated build outputCI 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.md

Requirements:

  1. At least 10 meaningful commits (not one giant dump)
  2. README with setup instructions
  3. One merged PR (even solo — practice the flow)
  4. CI workflow that runs at least one check
  5. No secrets in history

Link it on LinkedIn — recruiters clone repos, they don't read ZIP attachments.


Section 6 — Troubleshooting quick fixes

ProblemFix
Permission denied (publickey)Add SSH key to GitHub
rejected — non-fast-forwardgit pull then push
merge conflictEdit files, git add, commit
detached HEADgit switch main
Wrong branch committedgit switch -c rescue then cherry-pick or reset (see git3)
Committed to wrong branchgit switch correct-branch then git cherry-pick SHA

Section 7 — Full workflow diagram


Checklist

  • [ ] Cheat sheet commands feel familiar
  • [ ] Portfolio capstone repo is public on GitHub
  • [ ] CI green on main
  • [ ] Ready to use Git in Android and Python projects

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:

Capstone acceptance criteria

Common mistakes

  1. Documenting force-push as normal.
  2. Omitting .gitignore.
  3. 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.