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.
Official reference: Git docs & Pro Git
- 1.easy
app.jsis already tracked. What does the last command report?echo "v2" >> app.js git add app.js git commit -m "Update app" git reset HEAD~1 git status --short- Aapp.js modified and staged
- Bapp.js modified but unstaged
- CNothing: the tree is clean
- Dapp.js shown as deleted
Show answer
Answer: B (app.js modified but unstaged)
Plain
git resetdefaults 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).--softwould have left it staged;--hardwould have discarded it. - 2.easy
After
git reset --soft HEAD~1, where do the changes from the undone commit end up?- ADiscarded from disk
- BStaged in the index
- CUnstaged in the working tree
- DSaved as a new stash entry
Show answer
Answer: B (Staged in the index)
--softonly moves the branch pointer; the index and working tree keep the commit's content, so the changes appear staged and ready to recommit.--mixedwould unstage them and--hardwould discard them. Reset never creates a stash entry. - 3.easy
You edited tracked
app.jsand created a new, untrackednotes.txt, then rangit stash. What doesgit statusshow now?- ANothing: the tree is clean
- BOnly
notes.txt, as untracked - COnly
app.js, as modified - DBoth files, unchanged
Show answer
Answer: B (Only
notes.txt, as untracked)By default
git stashsaves only changes to tracked files, soapp.jsis reset while the untrackednotes.txtstays behind. Usegit stash -uto include untracked files, or-ato include ignored ones too. - 4.easy
Which command shows exactly the changes that the next
git commitwill record?- A
git diff - B
git diff HEAD - C
git diff --staged - D
git log -p -1
Show answer
Answer: C (
git diff --staged)git diff --staged(alias--cached) compares the index withHEAD, which is precisely what a commit records. Plaingit diffshows unstaged changes,git diff HEADmixes staged and unstaged, andgit log -p -1shows the previous commit. - A
- 5.easy
mainhas no new commits sincefeaturebranched from it. What doesgit merge featureonmaindo by default?- AMoves
mainforward tofeature - BCreates a two-parent merge commit
- CSquashes
featureinto one commit - DRebases
featureontomain
Show answer
Answer: A (Moves
mainforward tofeature)When the current branch is an ancestor of the one being merged, Git performs a fast-forward: it just moves the
mainpointer, with no new commit. A merge commit is created only when histories have diverged, or when you pass--no-ff. - AMoves
- 6.mid
Your local
mainandorigin/mainboth have new commits, and neitherpull.rebasenorpull.ffis configured. What doesgit pulldo in modern Git?- ACreates a merge commit automatically
- BRebases your local commits on top
- CRefuses and asks how to reconcile
- 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.rebaseorpull.ff, or passing--rebase,--no-rebaseor--ff-only. If the branch could simply fast-forward, pull would do that without asking. - 7.hard
While running
git rebase mainon yourfeaturebranch, a conflict stops the rebase. What doesgit checkout --theirs app.txtgive you?- AThe version from
main - BYour feature commit's version
- CThe merge-base version
- 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 (mainplus 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. - AThe version from
- 8.hard
What happens when you run
git reverton a merge commit without any options?- AIt deletes the merge commit
- BIt reverts both parents' changes
- CIt reverts the second parent's side
- 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.mid
A repository has only lightweight tags. What does plain
git describedo?- AUses the nearest lightweight tag
- BPrints the abbreviated commit SHA
- CPrints the current branch name
- DFails: no annotated tags found
Show answer
Answer: D (Fails: no annotated tags found)
By default
git describeonly 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.mid
On
mainyou rungit merge --squash featureand thengit commit. What doesgit branch -d featuredo next?- AFails: branch not fully merged
- BDeletes the branch normally
- CAsks you to confirm the deletion
- 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 frommainand Git considers the branch unmerged.-drefuses;git branch -Dforces the delete. - 11.mid
What does
git diff main...featureshow?- A
feature's changes since the merge base - BThe tip of
mainvs the tip offeature - CChanges on
mainsincefeaturebranched - DUncommitted changes on both branches
Show answer
Answer: A (
feature's changes since the merge base)With three dots,
git diff A...Bcompares 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 newmaincommits show up as reversed changes. - A
- 12.mid
In a script used with
git bisect run, what does exiting with code 125 mean?- AThe commit is bad
- BThe commit is good
- CSkip this commit
- 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.easy
config.jsonis already committed. You addconfig.jsonto.gitignoreand then edit the file. What doesgit statusshow?- A
config.jsonas modified - BNothing: the file is ignored
- C
config.jsonas deleted - DA warning about the ignore rule
Show answer
Answer: A (
config.jsonas 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.jsonand commit. - A
- 14.mid
When does
git push --force-with-lease(with no arguments) refuse to overwrite the remote branch?- AWhenever the push is not a fast-forward one
- BIf your branch has unpushed commits
- CIf the branch has no upstream configured
- 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.mid
You make a commit in detached HEAD state and then run
git switch main. What happens to that commit?- ADeleted as soon as you switch
- BMerged into
mainfor you - CUnreachable, but recoverable
- 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.easy
What does
git restore --staged app.jsdo?- ADiscards all edits to
app.js - BUnstages it but keeps your edits
- CRemoves
app.jsfrom the repository - DStashes only
app.js
Show answer
Answer: B (Unstages it but keeps your edits)
--stagedrestores the index entry fromHEAD, which unstages the file while leaving the working-tree changes alone. Discarding the edits would begit restore app.js; untracking it would begit rm --cached app.js. - ADiscards all edits to
- 17.hard
What does
git merge -s ours old-branchdo?- AMerges, resolving only conflicts in your favour
- BFast-forwards only if there are no conflicts
- CRebases the other branch onto yours
- DRecords a merge but keeps your tree unchanged
Show answer
Answer: D (Records a merge but keeps your tree unchanged)
The
oursstrategy creates a merge commit whose tree is identical to the current branch, ignoring everything fromold-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.mid
You run a plain
git clone(no extra flags) of a repository with a submodule atvendor/lib. What is invendor/lib?- AAn empty directory
- BThe files at the pinned commit
- CA symlink to the submodule URL
- 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.mid
In a GitHub Actions matrix with default settings, one of the matrix jobs fails. What happens to the others?
- AThey all keep running to completion
- BThe failed job is retried once first
- CQueued and running ones are cancelled
- DThey pause until a reviewer approves
Show answer
Answer: C (Queued and running ones are cancelled)
strategy.fail-fastdefaults to true, so GitHub cancels the in-progress and queued jobs in the matrix when any of them fails. Setfail-fast: falseto let every combination finish. Actions doesn't retry failed jobs automatically. - 20.mid
A workflow triggered by
pull_requestfrom a forked repository readssecrets.DEPLOY_KEY. What does it get?- AThe real value, masked in logs
- BAn empty value: no secrets for forks
- CThe value, once a maintainer approves
- 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.easy
The current version is
2.4.1. The next release containsfix: handle null pricesandfeat(api)!: remove v1 endpoints. Following Conventional Commits and SemVer, what is the new version?- A
2.4.2 - B
2.5.0 - C
2.5.1 - D
3.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 thefixwould give2.4.2and a plainfeatwould give2.5.0. - A
- 22.easy
Which deployment strategy keeps two full production environments and switches all traffic between them, allowing near-instant rollback?
- ABlue-green
- BCanary release
- CRolling update
- 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.mid
Which of these is NOT one of the DORA software delivery metrics?
- ADeployment frequency
- BChange failure rate
- CCode coverage
- 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.