# Git Quiz

## Question 1

What does `git add` do?

A) Commits your changes to the repository
B) Moves files from the working directory to the staging area
C) Creates a new file in the repository
D) Pushes your changes to a remote server

<!-- ANSWER: B -->
<!-- EXPLANATION: git add stages changes — it marks modified or new files to be included in the next commit. It moves them from the working directory to the staging area (index). It does NOT commit them or push them anywhere. -->

## Question 2

You have uncommitted changes on `main` and want to switch to another branch. What's the safest approach?

A) `git checkout other-branch` (just switch)
B) `git stash` then `git checkout other-branch`
C) `git reset --hard HEAD` then `git checkout other-branch`
D) `git commit -a -m "wip"` then `git checkout other-branch`

<!-- ANSWER: B -->
<!-- EXPLANATION: git stash temporarily saves your uncommitted changes so you can switch branches cleanly. Option A might fail or carry changes to the other branch. Option C would DESTROY your changes. Option D works but pollutes your commit history with "wip" commits. -->

## Question 3

What's the difference between `git fetch` and `git pull`?

A) They do the same thing
B) `fetch` downloads changes; `pull` downloads AND merges them
C) `fetch` is for branches; `pull` is for files
D) `pull` is faster because it skips the staging area

<!-- ANSWER: B -->
<!-- EXPLANATION: git fetch downloads changes from the remote but doesn't modify your working directory or current branch. git pull is essentially git fetch + git merge — it fetches AND integrates the changes. fetch is safer when you want to inspect changes before merging. -->

## Question 4

You accidentally committed a file with a secret API key. The commit has NOT been pushed. What should you do?

A) Delete the file and make a new commit
B) Use `git reset --soft HEAD~1` to undo the commit, remove the secret, recommit
C) Use `git revert HEAD` to undo the commit
D) Just add the file to `.gitignore`

<!-- ANSWER: B -->
<!-- EXPLANATION: git reset --soft HEAD~1 undoes the last commit but keeps changes staged. You can then remove the secret and recommit. Option A still leaves the secret in git history. Option C creates a revert commit but the secret remains in history. Option D only prevents future tracking, not past commits. Since the commit hasn't been pushed, reset is safe. -->

## Question 5

What happens when you create a new Git branch?

A) All files are copied to a new directory
B) A new pointer is created pointing to the current commit
C) A new repository is created
D) The working directory is cleared

<!-- ANSWER: B -->
<!-- EXPLANATION: A Git branch is just a lightweight pointer (40-byte file) to a commit SHA. No files are copied. This is why creating branches in Git is nearly instantaneous, unlike older version control systems like SVN that actually copied directories. -->

## Question 6

<!-- VISUAL: drag-order -->

Put these git commands in the correct order for a typical feature branch workflow:

A) `git add .`
B) `git checkout -b feature/my-feature`
C) `git push -u origin feature/my-feature`
D) `git commit -m "Implement feature"`

<!-- ANSWER: B,A,D,C -->
<!-- EXPLANATION: First create the branch (B), then stage changes (A), then commit (D), then push to set upstream (C). -->

## Question 7

<!-- VISUAL: drag-order -->

Put these steps in the correct order to resolve a merge conflict:

A) Edit the conflicted files to resolve the conflict
B) `git add` the resolved files
C) `git merge other-branch` (or pull, which triggers merge)
D) `git commit` to complete the merge

<!-- ANSWER: C,A,B,D -->
<!-- EXPLANATION: You merge first (C), which may create conflicts. Then edit the conflicted files (A), stage them (B), and commit to complete the merge (D). -->
