Git interview questions

14 questions from the Git Fundamentals: Commits, Branches and Collaboration course, each with the correct answer and an explanation. Try to answer before you open the answer.

Module 1: Getting Started

1. What does `git config --global` do?

  1. Applies the setting to only the current repo
  2. Uploads the setting to GitHub
  3. Applies the setting to every repo on the machine
  4. Deletes the repository
Show answer

Answer: Applies the setting to every repo on the machine

Global config lives in `~/.gitconfig` and is the default for every repo unless overridden locally.

Lesson: Configuring Your Identity

Module 3: The Basic Workflow

2. Which command shows staged changes not yet committed?

  1. git diff
  2. git log
  3. git status
  4. git diff --staged
Show answer

Answer: git diff --staged

Plain `git diff` compares working directory to the staging area; `--staged` compares staging area to the last commit.

Lesson: diff & log

Module 5: Merging

3. A merge conflict happens when...

  1. Two branches change the same lines differently
  2. You forget to run git status
  3. A branch is deleted before merging
  4. The remote is unreachable
Show answer

Answer: Two branches change the same lines differently

Git can auto-merge changes to different lines; overlapping edits need a human decision.

Lesson: Resolving Merge Conflicts

Module 8: Undoing Things

4. Which reset mode discards changes entirely?

  1. --soft
  2. --hard
  3. --mixed
  4. --keep
Show answer

Answer: --hard

--hard resets both the commit history and the working directory, deleting uncommitted work.

Lesson: git reset: soft, mixed, hard

5. Which command lists where HEAD has been, so you can recover lost commits?

  1. git reflog
  2. git log --stat
  3. git blame
  4. git remote -v
Show answer

Answer: git reflog

The reflog tracks HEAD movements, even after resets.

Lesson: Recovering Work with reflog

Module 11: Workflows

6. Which strategy favors small, frequent commits straight into one trunk?

  1. Git Flow
  2. Both equally
  3. Trunk-based development
  4. Neither
Show answer

Answer: Trunk-based development

Trunk-based development minimizes long-lived branches in favor of continuous integration into main.

Lesson: Git Flow vs Trunk-Based

7. What does git add do?

  1. Uploads to GitHub
  2. Deletes files
  3. Stages changes for the next commit
  4. Creates a branch
Show answer

Answer: Stages changes for the next commit

Staging selects what goes into the next commit.

Lesson: Git Flow vs Trunk-Based

8. Which command creates and switches to a new branch?

  1. git branch -d name
  2. git merge name
  3. git init name
  4. git switch -c name
Show answer

Answer: git switch -c name

-c creates the branch.

Lesson: Git Flow vs Trunk-Based

9. When does a merge conflict happen?

  1. Two branches change the same lines differently
  2. A branch is renamed
  3. The remote is offline
  4. You forget git status
Show answer

Answer: Two branches change the same lines differently

Git cannot choose between competing edits.

Lesson: Git Flow vs Trunk-Based

10. Which command safely undoes a pushed commit?

  1. git reset --hard
  2. git revert
  3. git rebase -i
  4. git stash
Show answer

Answer: git revert

revert adds a new commit that cancels the old one.

Lesson: Git Flow vs Trunk-Based

11. Which reset mode discards working changes?

  1. --soft
  2. --mixed
  3. --hard
  4. --keep-history
Show answer

Answer: --hard

--hard resets index and working tree.

Lesson: Git Flow vs Trunk-Based

12. Why avoid rebasing shared branches?

  1. It is slow
  2. It deletes tags
  3. It needs admin rights
  4. It rewrites history others already pulled
Show answer

Answer: It rewrites history others already pulled

Rewritten commits diverge from teammates' copies.

Lesson: Git Flow vs Trunk-Based

13. What does git stash do?

  1. Shelves uncommitted changes temporarily
  2. Deletes the repo
  3. Pushes to remote
  4. Renames a branch
Show answer

Answer: Shelves uncommitted changes temporarily

pop or apply brings them back.

Lesson: Git Flow vs Trunk-Based

14. Which command finds the commit that introduced a bug?

  1. git cherry-pick
  2. git bisect
  3. git remote
  4. git config
Show answer

Answer: git bisect

bisect binary-searches history between good and bad commits.

Lesson: Git Flow vs Trunk-Based

← Back to the course