Chapter 31 Quiz: Version Control Workflows
Test your understanding of version control workflows in AI-assisted development. Each question has one best answer unless otherwise noted. Try to answer each question before revealing the solution.
Question 1
What are the three areas of Git that every developer must understand?
Show Answer
**Working Directory, Staging Area (Index), and Repository (.git)** The working directory contains the files you edit (and where AI tools write code). The staging area is a holding zone for changes you intend to commit, allowing selective commits. The repository (.git directory) stores the complete history as a directed acyclic graph of commits.Question 2
Why does AI-assisted development require more version control discipline, not less?
Show Answer
AI tools generate code faster and in larger volumes than manual coding. This increased speed creates temptation to skip commits, delay reviews, and push large untested changes. More frequent checkpoints (commits) are needed because: (1) larger diffs are harder to review and debug, (2) AI-generated code may contain subtle errors that are only caught later, and (3) the ability to roll back to a known-good state is more valuable when changes are larger and more frequent.Question 3
Which branching strategy is best suited for a team with strong CI/CD that makes small, frequent commits using AI tools?
a) Gitflow b) Feature branch workflow c) Trunk-based development d) Release branch workflow
Show Answer
**c) Trunk-based development** Trunk-based development emphasizes small, frequent commits to the main branch with short-lived feature branches. This aligns well with AI-assisted development's fast pace and pairs naturally with strong CI/CD pipelines that catch issues quickly.Question 4
What is the correct Conventional Commits format for a commit message?
Show Answer
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Example: `feat(auth): add OAuth2 login flow`
Valid types include: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`, `perf`, `ci`, `build`. The subject line should be in imperative mood, under 50 characters, and not end with a period.
Question 5
Which of the following is NOT one of the seven rules of a great commit message?
a) Separate subject from body with a blank line b) Limit the subject line to 50 characters c) Use past tense in the subject line d) Use the body to explain what and why, not how
Show Answer
**c) Use past tense in the subject line** The correct rule is to use the *imperative mood* in the subject line. Write "Add feature" not "Added feature." Think of the commit message as completing the sentence "If applied, this commit will..." For example: "If applied, this commit will *add OAuth2 login flow*."Question 6
What is the primary advantage of squash merging for AI experimentation branches?
Show Answer
Squash merging collapses all commits from the feature branch into a single commit on the target branch. For AI experimentation branches, the commit history is often messy (e.g., "try approach A," "revert approach A," "try approach B," "fix approach B"). Squash merging produces a single clean commit with a meaningful message that describes the final result, not the process of how the AI generated it.Question 7
A merge conflict shows the following. What happened?
<<<<<<< HEAD
return calculate_tax(subtotal, state="CA")
=======
return calculate_tax(subtotal, include_shipping=True)
>>>>>>> feature/shipping
Show Answer
Two branches modified the same line of code. The `HEAD` branch (likely main) added a `state` parameter to the `calculate_tax` call. The `feature/shipping` branch added an `include_shipping` parameter to the same call. The correct resolution should likely include both parameters: `return calculate_tax(subtotal, state="CA", include_shipping=True)`. This requires understanding the intent of both changes, which is where AI assistance can help during conflict resolution.Question 8
When should you use git add -p instead of git add .?
Show Answer
Use `git add -p` (patch mode) when you want to selectively stage specific changes rather than all changes at once. This is especially important after AI-assisted coding sessions because: (1) the AI may have modified files you did not intend to change, (2) debug code or print statements may be mixed with production code, (3) you may want to split a large AI-generated change into multiple logical commits. Never blindly `git add .` after an AI interaction; always review the changes first.Question 9
What is semantic versioning, and what does each segment represent in v3.7.2?
Show Answer
Semantic versioning (SemVer) uses three numbers: `MAJOR.MINOR.PATCH`. In `v3.7.2`: - **3** (MAJOR): Incremented for incompatible/breaking API changes. - **7** (MINOR): Incremented for backward-compatible new features. - **2** (PATCH): Incremented for backward-compatible bug fixes. Rules: Increment PATCH for bug fixes with no API changes. Increment MINOR for new features that are backward compatible. Increment MAJOR for breaking changes. Pre-release versions use suffixes like `-beta.1` or `-rc.1`.Question 10
Which Git command helps you find the specific commit that introduced a bug using binary search?
a) git blame
b) git log --bisect
c) git bisect
d) git search
Show Answer
**c) `git bisect`** `git bisect` performs a binary search through the commit history. You mark the current commit as "bad" and a known-good commit as "good," and Git checks out commits between them for you to test. You can also automate it with `git bisect runQuestion 11
What is a Git worktree and when is it useful in AI-assisted development?
Show Answer
A Git worktree allows you to check out multiple branches simultaneously in different directories from the same repository. The command `git worktree addQuestion 12
What are the five most common issues to watch for when reviewing AI-generated code in a PR?
Show Answer
1. **Plausible but incorrect logic** — Code that looks correct at first glance but contains subtle bugs, especially in edge cases and boundary conditions. 2. **Outdated patterns** — Use of deprecated APIs, outdated libraries, or patterns that were common in older code but are no longer recommended. 3. **Security vulnerabilities** — SQL injection, hardcoded secrets, insufficient input validation, or insecure cryptographic practices. 4. **Missing error handling** — Focus on the happy path with missing try/except blocks, unchecked return values, or unhandled edge cases. 5. **Over-engineering** — Unnecessarily complex solutions when a simpler approach would suffice.Question 13
What is the purpose of a pre-commit hook, and why is it especially valuable when using AI coding tools?
Show Answer
A pre-commit hook is a script that runs automatically before a commit is created. It can check for linting errors, formatting issues, type errors, hardcoded secrets, and other problems. It is especially valuable with AI coding tools because: (1) AI-generated code may not follow your project's style or conventions, (2) AI may introduce security issues like hardcoded credentials, (3) AI-generated code might fail type checking or introduce linting violations, and (4) the pre-commit hook acts as an automated quality gate that catches issues before they enter the repository, regardless of who (or what) generated the code.Question 14
What is the difference between git merge --no-ff and git merge --ff-only?
Show Answer
- **`git merge --no-ff`** (no fast-forward): Always creates a merge commit, even if the merge could be performed as a fast-forward. This preserves the branch structure in the history, making it clear where a feature branch was created and merged. - **`git merge --ff-only`** (fast-forward only): Only performs the merge if it can be done as a fast-forward (i.e., the target branch has no new commits since the feature branch diverged). If a fast-forward is not possible, the merge fails. This enforces a linear history.Question 15
A monorepo contains a React frontend, a Python backend, and shared types. What is the main advantage of this structure for AI-assisted development?
Show Answer
The main advantage is **unified context**. AI tools can see the entire codebase in a single repository, enabling them to understand cross-component relationships. This means the AI can: (1) suggest frontend changes that correctly match backend API contracts, (2) update shared types and both consumers simultaneously, (3) perform cross-component refactoring in a single operation, and (4) make atomic commits that update multiple components together, ensuring consistency.Question 16
What does git reflog show, and why is it called a "safety net"?
Show Answer
`git reflog` shows a log of every change to HEAD, including operations that rewrite history such as rebase, reset, and amend. Unlike `git log`, which shows the commit history, the reflog records the movement of the HEAD pointer. It is called a safety net because it allows you to recover from almost any Git mistake. If you accidentally delete a branch, perform a bad rebase, or reset when you should not have, you can find the previous state in the reflog and recover it with `git checkout HEAD@{n}` or `git branch recovery HEAD@{n}`. The reflog keeps entries for 90 days by default.Question 17
What is the recommended PR size for effective code review, and why does AI-assisted development make it tempting to exceed this?
Show Answer
The recommended PR size is **under 400 lines of changes**. Research consistently shows that smaller PRs receive more thorough reviews, while large PRs tend to get rubber-stamped. AI-assisted development makes it tempting to exceed this because AI tools can generate large amounts of code quickly. A single AI interaction might produce an entire feature with hundreds of lines. The solution is to break AI output across multiple PRs, use stacked PRs for dependent changes, and commit AI experiments separately from the final implementation.Question 18
What is the Conventional Commits type for each of the following changes?
a) Adding a database index to speed up search queries b) Removing unused import statements c) Adding a new REST endpoint for user profiles d) Fixing a crash when the database connection times out e) Updating the README with new setup instructions
Show Answer
a) **`perf`** — Performance improvement (the index does not change functionality, it improves speed). b) **`style`** — Code formatting/cleanup that does not change behavior. c) **`feat`** — A new feature (new endpoint). d) **`fix`** — A bug fix (crash fix). e) **`docs`** — Documentation only change.Question 19
When is it appropriate to use git commit --no-verify to skip hooks?
Show Answer
Using `--no-verify` should be **rare and intentional**. Appropriate situations include: (1) emergency hotfixes where the pre-commit hooks take too long and the fix is urgent, (2) work-in-progress commits on a personal branch where the code is intentionally incomplete, or (3) commits that only modify non-code files (e.g., documentation) where code quality hooks are irrelevant. It should **never** be used to bypass failing hooks because the code "looks fine" or because the hooks are "too slow." If hooks are routinely skipped, the team should redesign the hook configuration (e.g., move slow tests to pre-push or CI instead of pre-commit).Question 20
What are the trade-offs between Git submodules and Git subtrees?
Show Answer
**Submodules:** - Link to a specific commit in an external repository. - Require special commands (`git submodule init`, `git submodule update`). - Do not clone automatically with the parent repository (need `--recurse-submodules`). - Easier to update the external dependency independently. - Can cause confusion if developers forget to update submodules. **Subtrees:** - Merge the external repository's code directly into your repository. - No special commands needed for cloning. - History is integrated into the parent repository. - Simpler for contributors who do not need to know about the external dependency. - Harder to push changes back to the external repository. **Subtrees are generally preferred** because they are simpler to manage and do not require contributors to learn special commands.Question 21
What does git stash push -m "WIP: AI-generated auth module" do, and when should you use this pattern in vibe coding?
Show Answer
This command temporarily saves all uncommitted changes (both staged and unstaged) with a descriptive message, reverting the working directory to the last commit state. In vibe coding, use this pattern when: (1) you want to try a new AI interaction but want a safety net to restore your current state, (2) you need to switch context (e.g., review a colleague's PR) without committing half-finished AI-generated code, or (3) you want to compare the current AI output with a clean state. The descriptive message (`-m` flag) is important because you may accumulate multiple stashes and need to identify them later.Question 22
Explain the difference between git rebase origin/main and git merge origin/main when updating a feature branch.
Show Answer
**`git rebase origin/main`:** Takes the commits from your feature branch, removes them temporarily, updates the branch to match `origin/main`, and then replays your commits on top. This creates a linear history where your feature commits appear after all the main branch commits. The commit hashes change (history is rewritten). **`git merge origin/main`:** Creates a merge commit that combines the history of both branches. Your original commits remain unchanged with their original hashes. The history shows the branching point and merge point. **For AI-assisted development:** Rebase is generally preferred for feature branches because it produces a cleaner history. However, never rebase branches that other people are working on, as the history rewrite will cause conflicts for their copies.Question 23
A team uses the following .pre-commit-config.yaml. What problem will they encounter?
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
Show Answer
**Black and Flake8 may conflict.** Black is an opinionated formatter that may produce code that violates some Flake8 rules (e.g., line length). If Black runs first and formats the code, Flake8 may then report violations on the Black-formatted code, causing the commit to fail. **Solution:** Configure Flake8 to be compatible with Black by setting `max-line-length = 88` in the Flake8 configuration (matching Black's default) and disabling rules that conflict with Black's formatting (e.g., `E203`, `W503`). Alternatively, use `flake8-black` or `pyproject-flake8` to ensure compatibility.Question 24
What is the "LGTM trap" in the context of AI-generated code reviews?
Show Answer
The "LGTM trap" (Looks Good To Me) is the tendency for reviewers to rubber-stamp AI-generated code with minimal review. Because AI-generated code is typically syntactically correct, well-formatted, and superficially logical, reviewers may lower their guard and approve it without thorough examination. This is dangerous because AI-generated code can contain: subtle logical errors, outdated patterns, security vulnerabilities, missing error handling, and unnecessary complexity. Reviewers should treat AI-generated code with the same rigor they would apply to code from a talented but inexperienced junior developer, looking specifically for the five common AI code issues (plausible but incorrect logic, outdated patterns, security vulnerabilities, missing error handling, and over-engineering).Question 25
Design a Git workflow for the following scenario: A 3-person team is building a web application using AI coding tools. They deploy to production twice a week. They want a clean Git history but also want the flexibility to experiment with AI-generated approaches. What branching strategy, merge strategy, and commit conventions would you recommend?