Back to sections

Git Quiz

Test what you actually know about Git. Free sample questions below, from easy to hard, with instant explanations.

easy

1. What is the staging area (also called the index) in Git?

A cloud backup service
The remote repository
An intermediate area where changes are collected before being included in a commitCorrect
A folder for deleted files

Think of the staging area as a holding pen between your files and your commit history: git add moves changes there, and only what's actually in that holding pen is what git commit will save, which is why you can choose to commit some changes but not others.

medium

2. What does `git blame <file>` show?

A list of everyone who has ever cloned the repository
The total number of bugs in a file
Which commit and author last modified each line of a fileCorrect
A file's complete diff history

git blame goes line by line through a file and tells you exactly which commit (and which author) last touched each one, which is exactly what you want when you're trying to figure out who wrote a weird line of code and why.

hard

3. You clone a project containing a submodule, `cd` into the submodule's directory, check out a different branch there, and make a commit. Later, `git status` in the parent repo shows the submodule as modified, even though you never touched any files in the parent repo itself. Why?

This only happens if you forgot to run `git submodule init`, and re-running it will permanently silence the warning
The parent repo's `.gitignore` is misconfigured and needs the submodule's path added to it
Submodules automatically sync all of their commits back into the parent repo's own history, so this indicates a bug
The parent repo tracks the submodule as a pointer to one exact commit SHA, and since the submodule's HEAD now points elsewhere, the parent sees that pointer as changed until you `git add` the submodule path and commit the update in the parent repoCorrect

A submodule reference in the parent repo is a pinned commit SHA recorded as a special "gitlink" entry, not a live link to a branch, so moving the submodule's checked-out commit makes the parent repo's working tree differ from what it last committed. That difference is exactly what `git status` is flagging: an uncommitted pointer change waiting for you to `git add` the submodule path and commit it in the parent. Nothing here is a bug or a `.gitignore` problem; it's the normal, if surprising, mechanics of how submodule pointers work.

easy

4. What does `git stash` do?

Permanently deletes all uncommitted changes from the working directory
Creates a new branch out of your uncommitted changes
Squashes your last few commits into a single commit
Temporarily shelves your uncommitted changes and resets the working directory to match HEAD, so you can switch context and restore them laterCorrect

`git stash` saves your staged and unstaged modifications to a hidden stack and cleans your working directory back to HEAD's state, which is useful when you need to switch branches without committing half-finished work. You later bring the changes back with `git stash pop` or `git stash apply`. It's easy to confuse with `git reset --hard`, but reset discards changes entirely instead of saving them.

medium

5. You accidentally committed a secret API key to a public repo and pushed it. What's the correct first step?

Rotate/revoke the leaked credential immediately, since it's already public regardless of what you do to the repoCorrect
Add the file to .gitignore going forward
Delete the repository and create a new one
Delete the commit with git commit --amend and force push

The moment you push, assume the key is already out in the wild, someone could have cloned or scraped it within seconds. Editing your commit history afterward doesn't undo that exposure, so the only thing that actually removes the risk is revoking or rotating the leaked credential itself, immediately.

hard

6. What does `git rebase --onto <newbase> <upstream> <branch>` let you do that a plain rebase cannot?

Delete a range of commits permanently with no way to recover them
Nothing different, it is identical to plain rebase
Merge two unrelated repositories
Replay a specific range of commits (from upstream to branch) onto an entirely different base commit, useful for moving a branch to a new parentCorrect

A regular rebase always replays your commits onto the tip of whatever branch you're rebasing onto. --onto is more surgical: it lets you say 'take just this range of commits and replay them onto this completely different commit instead', which is handy when a branch needs to move to a new starting point that isn't its original parent.

easy

7. What is a "remote" in Git?

A reference to a version of the repository hosted elsewhere, like on GitHubCorrect
A type of branch
A commit message format
A local backup folder

A remote is just a nickname (usually 'origin') that Git uses to remember where another copy of your repository lives, typically on a server like GitHub, so commands like push and pull know where to send or fetch changes.

medium

8. What does interactive rebase (`git rebase -i`) let you do?

Reorder, squash, edit, or drop commits before replaying them onto another branchCorrect
Only delete commits
Merge two unrelated repositories
Automatically resolve all conflicts

Interactive rebase opens up your recent commits as an editable list before replaying them, so instead of just moving them as-is, you can reorder them, squash several messy ones into a single clean commit, tweak a commit message, or drop a commit entirely.

hard

9. You need to find which of 200 commits introduced a regression, but manually checking out and testing each candidate by hand would take hours. How can you automate the entire bisection?

`git blame` on the affected file to see its most recent change
`git bisect skip` on every commit until one fails
`git bisect run ./test-script.sh`, letting Git automatically check out each candidate, run the script, and use its exit code to mark good/badCorrect
`git log -S"bug"` to search for the string that caused the bug

`git bisect run` takes a script or command, checks out each bisection candidate automatically, runs it, and uses the exit code to decide the next step: 0 means good, any code from 1 to 124 means bad, and the special code 125 means "can't test this commit, skip it." This turns what would be manual back-and-forth into a single unattended command that finishes with the exact first-bad commit already identified.

easy

10. You want Git to automatically run a linter and reject the commit outright if it fails, before the commit object is even created. Which mechanism should you set up?

A Git alias
A `post-merge` hook
A `pre-commit` hook script in `.git/hooks/`Correct
A rule in `.gitignore`

The pre-commit hook runs right before Git finalizes a commit, letting a script inspect the staged content and abort the commit, by exiting non-zero, if something's wrong, such as a failing linter. A post-merge hook only fires after a merge has already completed, so it can't block anything, and an alias is just a shortcut for typing commands, not an enforcement mechanism.

Ready for the real thing?

Take the full timed Git quiz and see your score.

    Welcome to OpsQuiz!

    Real scenario-based DevOps questions, hands-on practice, and clear explanations for every answer.