Documentation Index
Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
Use this file to discover all available pages before exploring further.
Git Fundamentals
Master the core concepts that make Git powerful: repositories, commits, and the staging area.Installing and Configuring Git
- Windows
- macOS
- Linux
First-Time Configuration
Creating Your First Repository
Method 1: Initialize a New Repository
.git directory contains all Git metadata: commits, branches, configuration, and the entire history.Method 2: Clone an Existing Repository
The Git Workflow
1. Working Directory
Your actual files where you make changes.2. Staging Area (Index)
Prepare changes for commit. The staging area is Git’s “shopping cart” — you browse the store (make changes in your working directory), add items to the cart (stage them), and checkout (commit) only when you are ready. You can add and remove items from the cart before committing, which means you control exactly what goes into each commit.3. Repository
Committed snapshots stored permanently.Understanding Commits
A commit is a snapshot of your entire project at a point in time. Not a diff, not a delta — a full snapshot. Git is smart enough to deduplicate identical files across snapshots (using content-addressable hashing), so this is efficient despite sounding wasteful. Every commit also records who made it, when, and a message explaining why.Anatomy of a Commit
Writing Good Commit Messages
Checking Status and History
Git Status
Git Log
Viewing Changes
Git Diff
Ignoring Files
Create a.gitignore file to exclude files from version control. This is not optional — without it, you will inevitably commit node_modules (300MB of dependencies), .env files (database passwords), or OS junk files (.DS_Store) that have no business in a repository.
Undoing Changes
Unstage Files
Discard Changes
Amend Last Commit
Practical Example: First Project
Let’s create a complete example:Common Workflows
Daily Development
Quick Fixes
Key Takeaways
Three States
Commit Often
Good Messages
Check Status
git status frequentlyPractice Exercises
Exercise 1: Basic Workflow
- Create a new repository
- Add 3 files
- Make 5 commits
- View the log with
--oneline --graph
Exercise 2: Staging
- Modify 3 files
- Stage only 2 of them
- Commit the staged files
- Commit the remaining file separately
Interview Deep-Dive
Explain the three states of a file in Git (modified, staged, committed) and why the staging area exists. Most version control systems go straight from 'changed' to 'committed' -- what does Git gain from the extra step?
Explain the three states of a file in Git (modified, staged, committed) and why the staging area exists. Most version control systems go straight from 'changed' to 'committed' -- what does Git gain from the extra step?
- In Git, a file passes through three states: modified (changed in your working directory but not yet staged), staged (marked for inclusion in the next commit via
git add), and committed (safely stored in the repository’s history as an immutable snapshot). - The staging area (also called the index) exists because it gives you editorial control over your commits. In SVN or Mercurial,
commitgrabs everything that changed. In Git, you decide exactly what goes in each commit. If you changed 10 files but only 3 are related to the bug fix you are committing, you stage those 3, commit with a clear message, then handle the remaining 7 in separate commits. - This enables atomic, logical commits. A single coding session might touch error handling, add a feature, and fix a typo. Without a staging area, all three go into one messy commit. With staging, you create three clean commits that can be reviewed, reverted, and bisected independently.
git add -ptakes this further by letting you stage individual hunks within a file. You can commit the bug fix on line 42 but leave the debug logging on line 100 unstaged. This level of granularity is impossible without a staging area.- Under the hood, the staging area is a binary file (
.git/index) that records which file versions (blob hashes) are ready for the next commit.git statuscompares three things: working directory vs index (unstaged changes), index vs HEAD commit (staged changes). This two-comparison model is whygit diffandgit diff --stagedshow different things.
git add -p in action — most developers are amazed the first time they see partial staging. The concrete habit I recommend: before committing, always run git diff --staged to review exactly what is going in. If the diff contains unrelated changes, unstage some with git restore --staged <file> and commit in batches.A new developer on your team accidentally committed a .env file containing database credentials to the repository. They then added .env to .gitignore and made another commit. Is the secret safe now? What do you do?
A new developer on your team accidentally committed a .env file containing database credentials to the repository. They then added .env to .gitignore and made another commit. Is the secret safe now? What do you do?
- The secret is not safe. Adding a file to
.gitignoreonly prevents future untracked files from being staged. It does not remove files that are already tracked. The.envfile is still in the Git history — anyone who clones the repository or browses the commit history can see it.git log -p -- .envwill show the full contents. - Immediate actions: First, rotate the database credentials right now. Assume they are compromised. Second, remove the file from tracking without deleting it from disk:
git rm --cached .envfollowed by a commit. This stops Git from tracking changes to.envgoing forward, but the historical commit still contains the file. - To remove the file from all history, use
git filter-repo --path .env --invert-paths. This rewrites every commit that touched.env, removing it entirely. This changes commit hashes, so all team members must re-clone or reset to the rewritten history. For public repositories on GitHub, you also need to contact GitHub support to purge cached data, because force-pushing does not immediately clear their CDN caches. - Prevention: set up a pre-commit hook (using Husky or a custom hook) that scans staged files for patterns matching secrets (API keys, passwords, connection strings). Tools like
git-secrets(AWS),gitleaks, orggshieldautomate this. Also, use.env.examplewith placeholder values committed to the repo, and.envin.gitignorefrom the very first commit.
What is the difference between 'git reset --soft', '--mixed', and '--hard'? Give me a scenario where you would use each.
What is the difference between 'git reset --soft', '--mixed', and '--hard'? Give me a scenario where you would use each.
- All three move the branch pointer (HEAD) to a different commit. The difference is what happens to the staging area (index) and the working directory.
--softmoves HEAD to the target commit but leaves the index and working directory unchanged. Everything that was in the “undone” commits becomes staged. Scenario: you made 5 small commits that should have been one.git reset --soft HEAD~5collapses them all into staged changes, and you re-commit with a single clean message. No work is lost.--mixed(the default) moves HEAD and resets the index to match the target commit, but leaves the working directory unchanged. Previously committed and staged changes become unstaged modifications. Scenario: you staged a file by mistake withgit add .and want to unstage everything.git reset HEAD(which is--mixedby default) unstages all files but keeps your edits.--hardmoves HEAD, resets the index, and overwrites the working directory to match the target commit. Uncommitted changes are permanently deleted. Scenario: your local branch is hopelessly mangled after a bad rebase, and you want to start fresh from the remote.git reset --hard origin/maindiscards everything local and syncs to the remote. Use with extreme caution — there is no undo for uncommitted work destroyed by--hard.- The mental model:
--softtouches only the commit history,--mixedtouches history and staging,--hardtouches everything. Each level is more destructive than the previous.
git reflog — find the SHA and create a branch. But uncommitted changes that were in the working directory are gone forever. Git never tracked them, so there is no reflog entry. The only hope is IDE local history (VS Code, IntelliJ, and others maintain their own file history) or filesystem-level recovery (Time Machine, file system snapshots). This is why I always tell developers: commit early and often, even WIP commits. A git reset --soft later can clean up the history, but uncommitted work is the one thing Git cannot protect.Next: Git Branching & Merging →