pencils ready ✎

Git & CI/CD MCQs multiple-choice questions with answers & explanations

All 23 Git & CI/CD quiz questions on one page. Pick an answer in your head, then open Show answer to check it and read why. Want a score and a timer? Take them as a quiz instead.

  1. 1.

    app.js is already tracked. What does the last command report?

    easy
    echo "v2" >> app.js
    git add app.js
    git commit -m "Update app"
    git reset HEAD~1
    git status --short
    1. Aapp.js modified and staged
    2. Bapp.js modified but unstaged
    3. CNothing: the tree is clean
    4. Dapp.js shown as deleted
    Show answer

    Answer: B (app.js modified but unstaged)

    Plain git reset defaults to --mixed: the branch moves back and the index is reset, but the working tree is untouched, so the edit survives as an unstaged change ( M app.js). --soft would have left it staged; --hard would have discarded it.

  2. 2.

    After git reset --soft HEAD~1, where do the changes from the undone commit end up?

    easy
    1. ADiscarded from disk
    2. BStaged in the index
    3. CUnstaged in the working tree
    4. DSaved as a new stash entry
    Show answer

    Answer: B (Staged in the index)

    --soft only moves the branch pointer; the index and working tree keep the commit's content, so the changes appear staged and ready to recommit. --mixed would unstage them and --hard would discard them. Reset never creates a stash entry.

  3. 3.

    You edited tracked app.js and created a new, untracked notes.txt, then ran git stash. What does git status show now?

    easy
    1. ANothing: the tree is clean
    2. BOnly notes.txt, as untracked
    3. COnly app.js, as modified
    4. DBoth files, unchanged
    Show answer

    Answer: B (Only notes.txt, as untracked)

    By default git stash saves only changes to tracked files, so app.js is reset while the untracked notes.txt stays behind. Use git stash -u to include untracked files, or -a to include ignored ones too.

  4. 4.

    Which command shows exactly the changes that the next git commit will record?

    easy
    1. Agit diff
    2. Bgit diff HEAD
    3. Cgit diff --staged
    4. Dgit log -p -1
    Show answer

    Answer: C (git diff --staged)

    git diff --staged (alias --cached) compares the index with HEAD, which is precisely what a commit records. Plain git diff shows unstaged changes, git diff HEAD mixes staged and unstaged, and git log -p -1 shows the previous commit.

  5. 5.

    main has no new commits since feature branched from it. What does git merge feature on main do by default?

    easy
    1. AMoves main forward to feature
    2. BCreates a two-parent merge commit
    3. CSquashes feature into one commit
    4. DRebases feature onto main
    Show answer

    Answer: A (Moves main forward to feature)

    When the current branch is an ancestor of the one being merged, Git performs a fast-forward: it just moves the main pointer, with no new commit. A merge commit is created only when histories have diverged, or when you pass --no-ff.

  6. 6.

    Your local main and origin/main both have new commits, and neither pull.rebase nor pull.ff is configured. What does git pull do in modern Git?

    mid
    1. ACreates a merge commit automatically
    2. BRebases your local commits on top
    3. CRefuses and asks how to reconcile
    4. DDiscards your local commits
    Show answer

    Answer: C (Refuses and asks how to reconcile)

    Modern Git stops with "Need to specify how to reconcile divergent branches" and suggests setting pull.rebase or pull.ff, or passing --rebase, --no-rebase or --ff-only. If the branch could simply fast-forward, pull would do that without asking.

  7. 7.

    While running git rebase main on your feature branch, a conflict stops the rebase. What does git checkout --theirs app.txt give you?

    hard
    1. AThe version from main
    2. BYour feature commit's version
    3. CThe merge-base version
    4. DThe pre-rebase working copy
    Show answer

    Answer: B (Your feature commit's version)

    A rebase replays your commits on top of main, so "ours" is the branch being built on (main plus already replayed commits) and "theirs" is the commit being replayed, your feature change. That is the reverse of a merge, where "ours" is your current branch.

  8. 8.

    What happens when you run git revert on a merge commit without any options?

    hard
    1. AIt deletes the merge commit
    2. BIt reverts both parents' changes
    3. CIt reverts the second parent's side
    4. DIt fails and asks for -m
    Show answer

    Answer: D (It fails and asks for -m)

    A merge has two parents, so Git can't tell which side to keep and refuses: "is a merge but no -m option was given". git revert -m 1 <merge> keeps the first parent (the branch merged into) and undoes what the other branch brought in. Revert never deletes commits.

  9. 9.

    A repository has only lightweight tags. What does plain git describe do?

    mid
    1. AUses the nearest lightweight tag
    2. BPrints the abbreviated commit SHA
    3. CPrints the current branch name
    4. DFails: no annotated tags found
    Show answer

    Answer: D (Fails: no annotated tags found)

    By default git describe only considers annotated tags, so it fails with "No annotated tags can describe..." and hints at --tags, which also uses lightweight ones. This is one reason releases should use annotated tags.

  10. 10.

    On main you run git merge --squash feature and then git commit. What does git branch -d feature do next?

    mid
    1. AFails: branch not fully merged
    2. BDeletes the branch normally
    3. CAsks you to confirm the deletion
    4. DUndoes the squash commit
    Show answer

    Answer: A (Fails: branch not fully merged)

    A squash merge creates an ordinary single-parent commit, so none of feature's commits are reachable from main and Git considers the branch unmerged. -d refuses; git branch -D forces the delete.

  11. 11.

    What does git diff main...feature show?

    mid
    1. Afeature's changes since the merge base
    2. BThe tip of main vs the tip of feature
    3. CChanges on main since feature branched
    4. DUncommitted changes on both branches
    Show answer

    Answer: A (feature's changes since the merge base)

    With three dots, git diff A...B compares the merge base of A and B with B, so you see only what the feature branch changed, like a pull request diff. git diff main feature (or two dots) compares the two tips directly, so new main commits show up as reversed changes.

  12. 12.

    In a script used with git bisect run, what does exiting with code 125 mean?

    mid
    1. AThe commit is bad
    2. BThe commit is good
    3. CSkip this commit
    4. DAbort the bisect
    Show answer

    Answer: C (Skip this commit)

    Exit 0 marks the commit good, 1 to 127 except 125 marks it bad, and 125 means it can't be tested (for example, it doesn't build), so bisect skips it. Other exit codes abort the run.

  13. 13.

    config.json is already committed. You add config.json to .gitignore and then edit the file. What does git status show?

    easy
    1. Aconfig.json as modified
    2. BNothing: the file is ignored
    3. Cconfig.json as deleted
    4. DA warning about the ignore rule
    Show answer

    Answer: A (config.json as modified)

    Ignore rules only affect untracked files. A tracked file keeps being tracked, so the edit shows up as a modification. To stop tracking it, run git rm --cached config.json and commit.

  14. 14.

    When does git push --force-with-lease (with no arguments) refuse to overwrite the remote branch?

    mid
    1. AWhenever the push is not a fast-forward one
    2. BIf your branch has unpushed commits
    3. CIf the branch has no upstream configured
    4. DIf the remote moved since your last fetch
    Show answer

    Answer: D (If the remote moved since your last fetch)

    The lease checks that the remote ref still equals your remote-tracking ref, the state you last fetched. If someone pushed in between, the push is rejected instead of silently deleting their commits. Non-fast-forward pushes are exactly what it is for, as long as the lease holds.

  15. 15.

    You make a commit in detached HEAD state and then run git switch main. What happens to that commit?

    mid
    1. ADeleted as soon as you switch
    2. BMerged into main for you
    3. CUnreachable, but recoverable
    4. DMoved onto a new branch
    Show answer

    Answer: C (Unreachable, but recoverable)

    No branch points to the commit, so switching away leaves it unreachable; Git warns and prints its SHA. It still exists and can be rescued with git branch <name> <sha> or via the reflog until garbage collection prunes it.

  16. 16.

    What does git restore --staged app.js do?

    easy
    1. ADiscards all edits to app.js
    2. BUnstages it but keeps your edits
    3. CRemoves app.js from the repository
    4. DStashes only app.js
    Show answer

    Answer: B (Unstages it but keeps your edits)

    --staged restores the index entry from HEAD, which unstages the file while leaving the working-tree changes alone. Discarding the edits would be git restore app.js; untracking it would be git rm --cached app.js.

  17. 17.

    What does git merge -s ours old-branch do?

    hard
    1. AMerges, resolving only conflicts in your favour
    2. BFast-forwards only if there are no conflicts
    3. CRebases the other branch onto yours
    4. DRecords a merge but keeps your tree unchanged
    Show answer

    Answer: D (Records a merge but keeps your tree unchanged)

    The ours strategy creates a merge commit whose tree is identical to the current branch, ignoring everything from old-branch; it is used to mark a branch as merged. Resolving only conflicting hunks in your favour is the strategy option -X ours, which still brings in the other side's non-conflicting changes.

  18. 18.

    You run a plain git clone (no extra flags) of a repository with a submodule at vendor/lib. What is in vendor/lib?

    mid
    1. AAn empty directory
    2. BThe files at the pinned commit
    3. CA symlink to the submodule URL
    4. DThe files from its latest commit
    Show answer

    Answer: A (An empty directory)

    The parent only stores a pointer to the submodule commit, so a plain clone leaves the directory empty. Run git submodule update --init --recursive, or clone with --recurse-submodules, to check out the pinned commit.

  19. 19.

    In a GitHub Actions matrix with default settings, one of the matrix jobs fails. What happens to the others?

    mid
    1. AThey all keep running to completion
    2. BThe failed job is retried once first
    3. CQueued and running ones are cancelled
    4. DThey pause until a reviewer approves
    Show answer

    Answer: C (Queued and running ones are cancelled)

    strategy.fail-fast defaults to true, so GitHub cancels the in-progress and queued jobs in the matrix when any of them fails. Set fail-fast: false to let every combination finish. Actions doesn't retry failed jobs automatically.

  20. 20.

    A workflow triggered by pull_request from a forked repository reads secrets.DEPLOY_KEY. What does it get?

    mid
    1. AThe real value, masked in logs
    2. BAn empty value: no secrets for forks
    3. CThe value, once a maintainer approves
    4. DA read-only, rotated copy
    Show answer

    Answer: B (An empty value: no secrets for forks)

    With the exception of GITHUB_TOKEN (which gets read-only permissions), secrets are not passed to the runner for workflows triggered from forks, so the expression evaluates to an empty string. Approving a first-time contributor's run doesn't change that.

  21. 21.

    The current version is 2.4.1. The next release contains fix: handle null prices and feat(api)!: remove v1 endpoints. Following Conventional Commits and SemVer, what is the new version?

    easy
    1. A2.4.2
    2. B2.5.0
    3. C2.5.1
    4. D3.0.0
    Show answer

    Answer: D (3.0.0)

    The ! marks a breaking change, which requires a MAJOR bump, and a major bump resets minor and patch to zero. On its own the fix would give 2.4.2 and a plain feat would give 2.5.0.

  22. 22.

    Which deployment strategy keeps two full production environments and switches all traffic between them, allowing near-instant rollback?

    easy
    1. ABlue-green
    2. BCanary release
    3. CRolling update
    4. DRecreate
    Show answer

    Answer: A (Blue-green)

    Blue-green deploys to the idle environment, then flips traffic at the load balancer; rolling back means flipping it back. A canary shifts a small percentage of traffic gradually, a rolling update replaces instances a few at a time, and recreate stops the old version before starting the new one.

  23. 23.

    Which of these is NOT one of the DORA software delivery metrics?

    mid
    1. ADeployment frequency
    2. BChange failure rate
    3. CCode coverage
    4. DLead time for changes
    Show answer

    Answer: C (Code coverage)

    DORA measures delivery throughput and stability: deployment frequency, lead time for changes, change failure rate, failed deployment recovery time and, more recently, deployment rework rate. Code coverage is a testing metric, not a DORA metric.

esc