Git Essentials — Commands, .gitignore, and GitHub All in One
Git Essentials — Commands, .gitignore, and GitHub All in One
🎯 By the End of This Lesson
After finishing this lesson, you will be able to confidently do the following three things.
- ▸✅ Git's three areas: working directory / staging area / repository
- ▸✅ Basic commands: commit · branch · merge
- ▸✅ Writing Conventional Commits messages
Keep the learning objectives as a checklist, and close the lesson once you can answer all of them.
The 6-Step Daily Git Workflow
1. Edit — Modify code in the Working Directory
2. git add — Move changed files → Staging Area
3. git commit -m — Move from Staging → Local Repo. Summarize changes with a message
4. git push — Local → Remote (GitHub). Share with your team
5. git pull — Remote changes → Local. Sync teammates' work
6. branch / merge — Branch by feature, merge into main when done
> 💡 Key concept: Edit (Working) → Stage (Staging) → Save (Repo) → Share (Remote) — a 4-step model.
.gitignore — Things You Must Never Push
1. New project — Copy and paste a template from github.com/github/gitignore (Node, Python, Java, etc.)
2. Pattern syntax — *.log (extension) / node_modules/ (folder) / !important.log (exception)
3. Verify — Check with git status. If files that should be ignored appear as untracked, they are missing from .gitignore
4. Already-committed files — Adding to .gitignore won't stop tracking. Use git rm --cached <file> to untrack
5. Global .gitignore — ~/.gitignore_global (shared across all projects, e.g. .DS_Store)
6. CI scanning — Scan for secret files with GitHub Actions using truffleHog or git-secrets
> ⚠️ Common mistake: missing .env, .key, .pem, .aws/credentials → secrets exposed. Once pushed, they remain in git history permanently.
6 Core GitHub Features
1. Repository — Project storage. public/private. README · LICENSE · .gitignore · .github/. fork · star · watch
2. Issues — Bugs, feature requests, discussions. label · milestone · assignee. Auto-linked to PRs (Closes #123)
3. Pull Request — Request to merge changes from a fork or branch into the original. Code review · CI · merge after approval
4. Actions (CI/CD) — .github/workflows/*.yml — auto build, test, deploy on push or PR. Free for public repos
5. Codespaces — VS Code + container inside the browser. No local setup required. Instant PR review and contribution
6. Copilot — AI pair programmer. Code autocomplete · PR summary · issue answers
> 🔗 GitHub founders: Tom Preston-Werner, Chris Wanstrath, PJ Hyett, Scott Chacon (2008) → acquired by Microsoft in 2018 → 100M+ developers in 2025.
git reset · revert · cherry-pick · stash — The *Four Undo Commands*
git reset — Time Travel to the Past
Comparing the 3 Options
The most common scenarios:
⚠️ Danger of reset --hard
- ▸Uncommitted changes are lost permanently
- ▸Resetting an already-pushed commit — conflicts with others + requires force push + breaks history
Never reset on shared branches. Local only.
git revert — Safe Undo for Public Branches
Adds a new "reverting commit". History is preserved; only the change is undone.
The standard approach when undoing a bad commit on the main branch. Works cleanly with other people's git pull.
reset vs revert in One Line
- ▸reset — Rewrites history. Local only.
- ▸revert — Adds a new reverting commit. Safe anywhere.
git cherry-pick — Pick a Specific Commit
Commonly used to backport a hotfix to a stable branch, or to merge only part of a large PR first.
git stash — Temporary Save
Scenario: You're mid-work and suddenly need to switch branches.
The standard way to move cleanly without committing.
.gitignore Practical Patterns
Write this immediately when starting a project. Use https://gitignore.io to auto-generate by tech stack.
Commit Messages — bad/good
Conventional Commits standard:
50 characters for the first line, wrap body at 72 characters. Use the imperative present tense in English.
🤖 Try Asking AI
- ▸"What git command cancels the last commit but keeps the changes in the staging area?"
- ▸"Write a Conventional Commits message for these changes."
- ▸"Review whether this .gitignore is sufficient for a Node.js + Python + Java environment."