1. What is Git and why is it widely used?
Difficulty: EasyType: SubjectiveTopic: Git Basics
Git is a distributed version control system (DVCS) created by Linus Torvalds for fast, reliable source control. It enables branching/merging, offline work, and full history on every clone—ideal for team collaboration and safe iteration.
2. What is a repository in Git? Differentiate local and remote repositories.
Difficulty: EasyType: SubjectiveTopic: Git Basics
A repository stores your project files and their version history. A local repo lives on your machine (.git); a remote repo (e.g., GitHub/GitLab) is a shared copy used for collaboration and backup.
3. What is the purpose of a .gitignore file? Give two common patterns.
Difficulty: EasyType: SubjectiveTopic: Gitignore
'.gitignore' tells Git which files/paths not to track (e.g., builds, secrets). Common patterns: 'node_modules/' and '*.log'. This keeps history clean and avoids committing noise or sensitive data.
Example Code
# .gitignore
node_modules/
*.log
.DS_Store
/dist/
4. Which statement best describes the difference between `git init` and `git clone`?
Difficulty: EasyType: MCQTopic: Git Basics
- `git init` creates a new empty repo; `git clone` copies an existing repo with history.
- Both commands create a new empty repository.
- `git init` downloads branches from remote; `git clone` stages files.
- `git init` only works online; `git clone` only works offline.
`git init` bootstraps a repository in the current folder; `git clone` fetches an existing repo, files, branches, and history.
Correct Answer: `git init` creates a new empty repo; `git clone` copies an existing repo with history.
5. What is the typical order for recording changes?
Difficulty: EasyType: MCQTopic: Git Workflow
- git commit → git add → git push
- git add → git commit → git push
- git push → git commit → git add
- git add → git push → git commit
Stage with `add`, create a snapshot with `commit`, then publish with `push`.
Correct Answer: git add → git commit → git push
6. What does `git add` do? What’s the staging area?
Difficulty: EasyType: SubjectiveTopic: Staging
`git add` places changes into the index (staging area), a buffer where you curate what will go into the next commit.
7. Which command pair helps you see staged vs. unstaged changes and actual line diffs?
Difficulty: MediumType: MCQTopic: Status Diff
- `git status` (state) and `git diff` (line changes)
- `git fetch` and `git merge`
- `git log` and `git blame`
- `git restore` and `git switch`
`status` summarizes tracked/untracked/staged; `diff` shows content differences.
Correct Answer: `git status` (state) and `git diff` (line changes)
8. Define a commit in Git. Why are commit messages important?
Difficulty: EasyType: SubjectiveTopic: Commits
A commit is a snapshot of staged changes with metadata (hash, author, time). Clear messages explain intent, aid code review, and improve traceability.
9. In a freshly cloned repo, what does the name `origin` refer to?
Difficulty: EasyType: MCQTopic: Remotes
- The default branch name
- The default remote pointing to the cloned URL
- The initial commit’s tag
- A local cache folder
`origin` is the default remote alias created by `git clone`.
Correct Answer: The default remote pointing to the cloned URL
10. Explain the difference between `git pull` and `git fetch`.
Difficulty: MediumType: SubjectiveTopic: Fetch Pull
`git fetch` downloads new refs/history without altering your working branch. `git pull` = fetch + merge (or rebase), integrating changes into the current branch.
11. Which command both creates and switches to a new branch named `feature/ui`?
Difficulty: MediumType: MCQTopic: Branching
- `git branch feature/ui`
- `git checkout feature/ui`
- `git checkout -b feature/ui`
- `git switch -c feature/ui`
Modern Git: `git switch -c <name>` creates and checks out. Classic equivalent: `git checkout -b <name>`.
Correct Answer: `git switch -c feature/ui`
12. What is a merge conflict and how do you resolve it?
Difficulty: MediumType: SubjectiveTopic: Conflicts
A conflict arises when Git can’t auto-merge edits (e.g., same line differs). Open files, choose the correct content, save, `git add` the fixes, then `git commit` (or `--continue`).
13. What does `git stash` do by default?
Difficulty: MediumType: MCQTopic: Stash
- Commits all changes with a temporary message
- Temporarily shelves uncommitted changes and reverts to a clean work tree
- Deletes untracked files
- Pushes staged changes to the remote
`git stash` saves local modifications (tracked files) for later: use `stash pop/apply` to restore.
Correct Answer: Temporarily shelves uncommitted changes and reverts to a clean work tree
14. When would you use `git commit --amend` and what are the risks?
Difficulty: MediumType: SubjectiveTopic: Commit Amend
Use it to fix the last commit’s message or add missed changes. It rewrites history, so avoid amending commits already pushed/shared.
15. What problem does branching solve in Git and why is it cheap compared to other VCSs?
Difficulty: EasyType: SubjectiveTopic: Branching
Branches let you isolate work (features, fixes, experiments) without disrupting the main line. In Git, branches are lightweight pointers to commits, so creating/switching is fast and storage-efficient.
16. Which command uses the modern syntax to create and switch to a branch named `feature/api`?
Difficulty: EasyType: MCQTopic: Branching
- git branch feature/api && git checkout feature/api
- git checkout -b feature/api
- git switch -c feature/api
- git checkout feature/api
`git switch -c <name>` is the newer, intent-specific command. The classic equivalent is `git checkout -b <name>`.
Correct Answer: git switch -c feature/api
17. How do you set the current local branch to track `origin/develop`?
Difficulty: MediumType: MCQTopic: Tracking Branch
- git branch --set-upstream-to=origin/develop
- git push --set-upstream origin develop
- git remote add upstream origin/develop
- git set-upstream origin develop
Use `git branch --set-upstream-to=<remote>/<branch>` from the local branch. Alternatively, the first push can set it: `git push --set-upstream origin <branch>`.
Correct Answer: git branch --set-upstream-to=origin/develop
18. Explain fast-forward merge vs `--no-ff`. When would you prefer `--no-ff`?
Difficulty: MediumType: SubjectiveTopic: Fast Forward
A fast-forward moves the branch pointer when no divergent commits exist; no merge commit is created. `--no-ff` forces a merge commit to preserve feature-branch context—useful for code review traceability and keeping logical units in history.
19. Which command merges the branch `feature/ui` into your current branch?
Difficulty: EasyType: MCQTopic: Merging
- git rebase feature/ui
- git merge feature/ui
- git pull feature/ui
- git switch feature/ui
`git merge <branch>` integrates that branch into the current HEAD.
Correct Answer: git merge feature/ui
20. Contrast `git rebase` and `git merge` in collaboration. Mention risks and best practices.
Difficulty: MediumType: SubjectiveTopic: Merge Rebase
`merge` combines histories and may create a merge commit; it preserves chronology from all contributors. `rebase` rewrites commits on top of a new base for a linear history—clean but dangerous if used on shared/pushed commits. Rebase private branches; avoid rebasing public history.
21. After a merge conflict, which sequence completes the merge?
Difficulty: MediumType: MCQTopic: Conflicts
- Fix files → git add <files> → git commit
- Fix files → git commit
- git add . → git merge --continue → git commit
- git reset --hard → git commit
Edit to resolve, stage resolved files, then commit. During rebase, you’d use `git rebase --continue` after `git add`.
Correct Answer: Fix files → git add <files> → git commit
22. Your new branch `bugfix/typo` has no upstream. What sets it and pushes once?
Difficulty: EasyType: MCQTopic: Push
- git push origin
- git push --set-upstream origin bugfix/typo
- git branch --set-upstream-to=origin/bugfix/typo
- git remote add origin bugfix/typo
First push with `--set-upstream` ties the local branch to its remote tracking branch.
Correct Answer: git push --set-upstream origin bugfix/typo
23. What does `git cherry-pick` do? Provide a use case.
Difficulty: MediumType: SubjectiveTopic: Cherry Pick
`git cherry-pick <hash>` applies the changes from a specific commit onto the current branch. Commonly used to backport a hotfix commit from `main` to a release branch without merging all other changes.
24. Which command is safer to undo a public commit on a shared branch?
Difficulty: MediumType: MCQTopic: Undo Changes
- git reset --hard <hash>
- git revert <hash>
- git restore --source <hash> .
- git clean -fd
`revert` creates a new commit that negates the changes without rewriting history, safe for shared branches.
Correct Answer: git revert <hash>
25. To integrate upstream changes without a merge commit, which command would you use?
Difficulty: MediumType: MCQTopic: Fetch Pull
- git pull
- git pull --rebase
- git merge --squash
- git fetch --all
`pull --rebase` rewrites local work on top of fetched commits, avoiding a merge commit for a linear history.
Correct Answer: git pull --rebase
26. Give two `git log` flags useful during reviews and explain them.
Difficulty: EasyType: SubjectiveTopic: Git Log
`--oneline --graph --decorate` for a compact, visual branch graph; `--stat` to see per-file change summary; `-p` to display patch/diffs for each commit.
27. Which commands remove a merged local branch and then prune remote-tracking branches no longer on the server?
Difficulty: EasyType: MCQTopic: Branch Cleanup
- `git branch -d <name>` then `git fetch --prune`
- `git branch -D <name>` then `git pull`
- `git reset --hard` then `git fetch`
- `git prune` then `git branch -d <name>`
Use `-d` for safe deletion (already merged). `git fetch --prune` cleans stale remote-tracking refs.
Correct Answer: `git branch -d <name>` then `git fetch --prune`
28. Why prefer annotated tags for releases and how do you push one?
Difficulty: EasyType: SubjectiveTopic: Tags
Annotated tags store tagger, date, and message—ideal for releases. Create with `git tag -a v1.2 -m "Release"` and push using `git push origin v1.2`.
29. What is the Git Index (staging area) and why does Git use it?
Difficulty: EasyType: SubjectiveTopic: Staging
The Index is a middle layer between your working tree and the repository. You choose exactly which changes to include in the next snapshot (commit), enabling partial commits and clean, reviewable history.
30. Which command stages all modified and deleted files but not untracked files?
Difficulty: EasyType: MCQTopic: Staging
- git add .
- git add -A
- git add -u
- git add --all :/
`-u` stages tracked file modifications and deletions; it skips new untracked files.
Correct Answer: git add -u
31. How do you stage only parts (hunks) of a file interactively?
Difficulty: MediumType: MCQTopic: Staging
- git add -p
- git commit -p
- git stage --interactive
- git patch add
`git add -p` lets you review and stage hunks interactively for granular commits.
Correct Answer: git add -p
32. Describe two best practices for writing commit messages.
Difficulty: EasyType: SubjectiveTopic: Commit Hygiene
Keep subject line ≤50 chars in imperative mood (e.g., "Fix crash on null input"). Add a blank line, then a body explaining what and why (context, impact, links).
33. You forgot to include one file in the last commit. Which sequence is correct?
Difficulty: EasyType: MCQTopic: Commit Amend
- git commit --amend; git add missing.js
- git add missing.js; git commit --amend
- git reset --hard; git commit --amend
- git stash; git commit --amend
Stage the missing change, then amend to rewrite the tip commit (avoid on public history).
Correct Answer: git add missing.js; git commit --amend
34. Which command unstages a file but keeps its working tree changes?
Difficulty: EasyType: MCQTopic: Staging
- git restore --staged <file>
- git checkout -- <file>
- git reset --hard <file>
- git clean -fd
`restore --staged` removes from Index only; the file contents remain in the working tree.
Correct Answer: git restore --staged <file>
35. Compare `git reset --soft`, `--mixed` (default), and `--hard`.
Difficulty: MediumType: SubjectiveTopic: Reset
`--soft` moves HEAD only (keeps Index/WT), `--mixed` moves HEAD and resets Index (keeps WT), `--hard` resets HEAD, Index, and Working Tree (destructive).
36. Which command shows a compact, decorated graph of commits for review?
Difficulty: EasyType: MCQTopic: Git Log
- git log --oneline --graph --decorate --all
- git log -p
- git reflog --graph
- git show --graph
This combo visualizes branch tips and relationships succinctly across all refs.
Correct Answer: git log --oneline --graph --decorate --all
37. What is `git reflog` and when is it indispensable?
Difficulty: MediumType: SubjectiveTopic: Reflog
Reflog records movements of HEAD and refs (even orphaned). It’s crucial for recovering "lost" commits after resets/rebases or branch deletions.
38. Which command compares staged changes to the last commit?
Difficulty: MediumType: MCQTopic: Status Diff
- git diff
- git diff --staged
- git diff HEAD
- git show --name-only
`--staged` (aka `--cached`) shows Index vs HEAD; plain `git diff` shows WT vs Index.
Correct Answer: git diff --staged
39. You want to discard local changes in `app.js` and reset it to the last commit. Modern command?
Difficulty: MediumType: MCQTopic: Restore
- git checkout -- app.js
- git restore app.js
- git reset --hard app.js
- git clean app.js
`git restore <path>` replaces the file from HEAD (modern replacement for `checkout --`).
Correct Answer: git restore app.js
40. How do you find a commit by message and then show its patch?
Difficulty: MediumType: SubjectiveTopic: Git Log
Use `git log --grep "keyword"` to locate by message; then `git show <hash>` (optionally `-p --stat`) to view the diff and metadata.
41. Which flag creates a GPG-signed commit (assuming GPG is configured)?
Difficulty: MediumType: MCQTopic: Signed Commits
- git commit -S -m "msg"
- git commit --sign -m "msg"
- git commit --gpg -m "msg"
- git commit --secure -m "msg"
`-S` signs the commit. Configure with `user.signingkey` and GPG agent beforehand.
Correct Answer: git commit -S -m "msg"
42. Explain `git commit --fixup` and `git rebase --autosquash` workflow.
Difficulty: MediumType: SubjectiveTopic: Autosquash
`--fixup <hash>` creates a targeted fix commit labeled for autosquash. Later `rebase -i --autosquash` reorders and squashes fixups onto their intended commits automatically, keeping a tidy history.
43. What is a remote in Git and why do most repositories have one named 'origin'?
Difficulty: EasyType: SubjectiveTopic: Remotes
A remote is a named reference to another copy of the repository, typically hosted on a server. 'origin' is the default name Git assigns when you clone, pointing back to the source repository. It lets you fetch, pull, and push changes for collaboration.
44. Which command changes the URL of the existing 'origin' remote?
Difficulty: EasyType: MCQTopic: Remotes
- git remote rename origin <new-url>
- git remote set-url origin <new-url>
- git set remote origin <new-url>
- git config remote.origin.url <new-url>
`git remote set-url` updates the fetch/push URLs for a named remote.
Correct Answer: git remote set-url origin <new-url>
45. What is an upstream (tracking) branch and how do you set it for the current branch?
Difficulty: MediumType: SubjectiveTopic: Tracking Branch
An upstream branch is the remote branch your local branch integrates with by default for pull/push. Set it via `git branch --set-upstream-to=origin/main` or on first push using `git push -u origin <branch>`.
46. Which statement is TRUE?
Difficulty: EasyType: MCQTopic: Fetch Pull
- `git pull` is equivalent to `git fetch` followed by `git merge` (or rebase per config).
- `git fetch` overwrites local commits.
- `git pull` never creates merge commits.
- `git fetch` updates your working tree files.
`pull` first fetches remote tracking changes then integrates them, while `fetch` only updates remote-tracking refs.
Correct Answer: `git pull` is equivalent to `git fetch` followed by `git merge` (or rebase per config).
47. How do you remove remote-tracking refs that no longer exist on the server when fetching?
Difficulty: EasyType: MCQTopic: Branch Cleanup
- git fetch --clean
- git fetch --gc
- git fetch --prune
- git remote prune --all-only
`--prune` deletes local stale remote-tracking branches (e.g., origin/feature-x) removed from the remote.
Correct Answer: git fetch --prune
48. Explain the difference between `git push` (with default `push.default=simple`) and `git push --all`.
Difficulty: MediumType: SubjectiveTopic: Push
`push.default=simple` pushes the current branch to its upstream of the same name and rejects if names differ. `git push --all` pushes all local branches that have matching names to the remote.
49. Which command deletes a branch named `feature/login` on the `origin` remote?
Difficulty: EasyType: MCQTopic: Branch Cleanup
- git branch -D origin/feature/login
- git push origin :feature/login
- git rm origin/feature/login
- git remote rm feature/login
Pushing an empty ref (`:<name>`) deletes the remote branch. Modern alternative: `git push origin --delete feature/login`.
Correct Answer: git push origin :feature/login
50. To pull by rebasing your local commits on top of fetched changes just this time, use:
Difficulty: MediumType: MCQTopic: Pull Rebase
- git pull --merge
- git pull --no-ff
- git pull --rebase
- git pull --squash
`--rebase` linearizes history by replaying local commits over the updated upstream.
Correct Answer: git pull --rebase
51. Differentiate lightweight and annotated tags. When would you prefer each?
Difficulty: MediumType: SubjectiveTopic: Tags
Lightweight tags are simple pointers to a commit. Annotated tags (`git tag -a`) store metadata (tagger, date, message, GPG sig). Use annotated tags for releases; lightweight tags for local/bookmark usage.
52. Which command pushes all local tags to the `origin` remote?
Difficulty: EasyType: MCQTopic: Tags
- git push origin --all-tags
- git push origin --tags
- git push --tags origin main
- git push origin tags/*
`--tags` tells Git to send all tag refs to the target remote.
Correct Answer: git push origin --tags
53. You need a fast clone of a huge repo without full history. Which option is correct?
Difficulty: MediumType: MCQTopic: Shallow Clone
- git clone --depth 1 <url>
- git clone --shallow=1 <url>
- git clone --partial <url>
- git clone --latest <url>
`--depth 1` creates a shallow clone with truncated history for speed and reduced size.
Correct Answer: git clone --depth 1 <url>
54. Why might a repo have both `origin` and `upstream` remotes? Outline a common workflow.
Difficulty: MediumType: SubjectiveTopic: Remotes
In fork-based workflows, `origin` is your fork; `upstream` is the source project. You fetch from `upstream` to stay current, rebase your feature branch, push to `origin`, and open a PR back to `upstream`.
55. What is a Git submodule and how do you initialize and update them after cloning?
Difficulty: MediumType: SubjectiveTopic: Submodules
A submodule embeds another repo at a specific commit. After cloning, run `git submodule init` then `git submodule update` (or `git submodule update --init --recursive`) to fetch and checkout submodule contents.
56. You want to work on two branches simultaneously from the same repo without stashing. What feature helps?
Difficulty: MediumType: MCQTopic: Worktrees
- git subtree
- git worktree
- git split
- git bundle
`git worktree add ../path <branch>` creates another working tree tied to the same `.git` data, enabling parallel checkouts.
Correct Answer: git worktree
57. Compare Git Flow, GitHub Flow, and Trunk-based development. When would you prefer each?
Difficulty: MediumType: SubjectiveTopic: Branch Models
Git Flow favors release cycles (develop, release, hotfix) for products with scheduled releases. GitHub Flow suits continuous delivery with short-lived feature branches and PRs to main. Trunk-based emphasizes committing to main behind flags with tiny branches for rapid integration. Choose based on cadence, compliance, and team size.
58. Which statement about merge vs rebase is MOST accurate?
Difficulty: EasyType: MCQTopic: Merge Rebase
- Rebase preserves all merge commits by default.
- Merge rewrites history; rebase never rewrites history.
- Rebase rewrites commits onto a new base to create linear history; merge preserves branch topology.
- Both merge and rebase always create new commits.
Rebase copies your commits onto the target tip (new IDs), producing a straight line; merge records a join, keeping parallel history.
Correct Answer: Rebase rewrites commits onto a new base to create linear history; merge preserves branch topology.
59. What does `git merge --no-ff feature` do when a fast-forward would be possible?
Difficulty: EasyType: MCQTopic: Fast Forward
- Aborts the merge.
- Forces a merge commit to preserve the feature branch identity.
- Squashes all commits into one.
- Rebases `feature` onto current branch before merging.
`--no-ff` creates a merge commit even if HEAD could fast-forward, keeping branch context for later tracing/reverts.
Correct Answer: Forces a merge commit to preserve the feature branch identity.
60. How do you squash the last 3 commits into one with an edited message using interactive rebase?
Difficulty: MediumType: SubjectiveTopic: Rebase
Run `git rebase -i HEAD~3`; change second/third `pick` to `squash` (or `fixup`); save, then edit the combined message and complete the rebase.
61. You made a fixup commit with message `fixup! Parse config`. Which command auto-positions it during rebase?
Difficulty: MediumType: MCQTopic: Autosquash
- git rebase -i --fixup HEAD~10
- git rebase -i --autosquash origin/main
- git rebase --auto HEAD
- git merge --autosquash
`--autosquash` pairs `fixup!`/`squash!` commits with their targets in the todo list.
Correct Answer: git rebase -i --autosquash origin/main
62. Why is it unsafe to rebase public branches and when is it acceptable?
Difficulty: EasyType: SubjectiveTopic: Git Workflow
Rebasing rewrites commit IDs, breaking collaborators’ histories. It’s safe on private/local branches before pushing or when everyone coordinates (e.g., force-push with lease) and consumers are ready.
63. During a rebase you resolve conflicts. Which sequence continues correctly?
Difficulty: MediumType: MCQTopic: Conflicts
- Edit → git add → git rebase --continue
- Edit → git add → git commit → git rebase --continue
- Edit → git rebase --skip → git add
- Edit → git rebase --abort → git add
Stage the resolved files and continue. You do not create a manual commit during rebase steps.
Correct Answer: Edit → git add → git rebase --continue
64. When would you use `git rebase --onto <newbase> <upstream> <branch>`? Give a practical example.
Difficulty: MediumType: SubjectiveTopic: Rebase
Use it to transplant a range of commits onto a different base, skipping earlier ones. Example: move `featureA` commits that diverged from `topic` onto `main`: `git rebase --onto main topic featureA`.
65. What is the effect of using a platform’s “Squash and merge” option on a PR?
Difficulty: EasyType: MCQTopic: Squash Merge
- All commits are preserved and a merge commit is added.
- All commits from the PR are condensed into a single commit on the target branch.
- It rebases the PR onto target and keeps all commits.
- It deletes the feature branch without merging.
Squash merge maintains a clean history with one commit representing the PR.
Correct Answer: All commits from the PR are condensed into a single commit on the target branch.
66. Which merge strategy option prefers current branch changes on conflicts?
Difficulty: MediumType: MCQTopic: Merge Policy
- git merge -s ours
- git merge -X ours
- git merge -s theirs
- git merge -X theirs
`-X ours` is a strategy option for the recursive strategy preferring current branch on a path-level conflict; `-s ours` discards the other tree entirely.
Correct Answer: git merge -X ours
67. What is an octopus merge and when is it appropriate?
Difficulty: MediumType: SubjectiveTopic: Advanced Merge
An octopus merge merges more than two branches in a single commit. It’s suitable for merging many independent topic branches without conflicts; avoid when manual conflict resolution is required.
68. What does `git rerere` help with?
Difficulty: MediumType: MCQTopic: Conflicts
- Automatically reverts erroneous commits.
- Remembers how you resolved a conflict and reapplies it next time the same conflict appears.
- Records rebase steps for replay.
- Rebuilds remote refs after prune.
Enable with `git config rerere.enabled true` to speed repeated merges/rebases with identical conflicts.
Correct Answer: Remembers how you resolved a conflict and reapplies it next time the same conflict appears.
69. You accidentally finished a destructive rebase. How do you recover your previous branch state?
Difficulty: MediumType: SubjectiveTopic: Reflog
Use `git reflog` to find the pre-rebase HEAD (e.g., `HEAD@{1}`) and `git reset --hard <that-id>` or create a rescue branch from it. Reflog records past HEAD positions.
70. A team wants a clean linear main branch and to preserve PR context. Which policy fits best?
Difficulty: EasyType: MCQTopic: Merge Policy
- Require rebase before merging + use squash merge for PRs.
- Disallow rebases; only allow merge commits.
- Force fast-forward merges only; no PR reviews.
- Disable CI on PRs to speed up merges.
Rebasing avoids merge bubbles, and squashing yields a single, reviewed commit per PR while PR metadata preserves context.
Correct Answer: Require rebase before merging + use squash merge for PRs.
71. Differentiate between working tree, index (staging area), and HEAD.
Difficulty: EasyType: SubjectiveTopic: Git Basics
Working tree = your files on disk; index = staged snapshot for the next commit; HEAD = pointer to the last commit of the current branch. Most history edits move HEAD; file-level fixes move working tree or index.
72. Which command moves HEAD and updates the index but leaves the working tree unchanged?
Difficulty: EasyType: MCQTopic: Reset
- git reset --hard <commit>
- git reset --mixed <commit>
- git reset --soft <commit>
- git restore --staged .
`--mixed` (default) moves HEAD and resets index to the commit, keeping your working files.
Correct Answer: git reset --mixed <commit>
73. When should you prefer `git revert` over `git reset`?
Difficulty: MediumType: MCQTopic: Undo Changes
- When you are cleaning local WIP before the first push.
- When you need to undo a public commit without rewriting shared history.
- When you want to rewrite author info on past commits.
- When you want to discard untracked files.
`revert` adds a new commit that negates a past one; safe for shared branches.
Correct Answer: When you need to undo a public commit without rewriting shared history.
74. What happens after `git reset --soft HEAD~2` and why is it useful?
Difficulty: EasyType: SubjectiveTopic: Reset
HEAD moves back two commits; index and working tree keep the changes from those commits staged. Useful to reword/squash into a single commit.
75. Which data is lost after `git reset --hard <commit>` (assuming no reflog usage)?
Difficulty: MediumType: MCQTopic: Reset Safety
- Only untracked files
- Only the index; working tree remains
- Both index and working tree changes since that commit
- Remote branches
`--hard` aligns index and working tree to the target commit; untracked files remain unless cleaned.
Correct Answer: Both index and working tree changes since that commit
76. Explain `git restore` and `git restore --staged` as modern replacements for older patterns.
Difficulty: MediumType: SubjectiveTopic: Restore
`git restore <path>` restores file content in working tree from HEAD (or a commit). `git restore --staged <path>` un-stages changes (like `git reset <path>`). They split file restore from branch switching for clarity.
77. You need to undo only commit abc123 on main and keep later commits intact. What is correct?
Difficulty: MediumType: MCQTopic: Revert
- git reset --hard abc123^
- git revert abc123
- git rebase -i abc123
- git checkout abc123 -- . && git commit
Revert creates a new inverse commit, preserving subsequent history.
Correct Answer: git revert abc123
78. You force-pushed the wrong history and lost your local branch tip. How can `git reflog` help you recover?
Difficulty: MediumType: SubjectiveTopic: Reflog
Use `git reflog` to find the previous HEAD (e.g., `HEAD@{2}`) then `git branch rescue HEAD@{2}` or `git reset --hard <that-id>` to restore the state.
79. You checked out a commit SHA directly. Which is TRUE?
Difficulty: EasyType: MCQTopic: Detached HEAD
- You are in detached HEAD; new commits won’t belong to a branch unless you create one.
- You created a new branch automatically.
- You cannot commit in this state.
- Pushing will always create a tag.
Create a branch (`git switch -c`) if you intend to keep commits.
Correct Answer: You are in detached HEAD; new commits won’t belong to a branch unless you create one.
80. How do you unstage only `app/config.yml` while keeping edits in your working tree?
Difficulty: MediumType: SubjectiveTopic: Reset
`git restore --staged app/config.yml` (or `git reset app/config.yml`) removes it from the index but leaves file changes on disk.
81. Which sequence discards all local tracked changes and resets to origin/main?
Difficulty: MediumType: MCQTopic: Restore
- git fetch origin && git reset --hard origin/main
- git pull --rebase && git clean -fdx
- git revert HEAD..origin/main
- git restore --staged . && git restore .
Fetch updates, then hard-reset branch to the remote tip (tracked files).
Correct Answer: git fetch origin && git reset --hard origin/main
82. How do you revert a range of commits from A (older) to B (newer) in one go?
Difficulty: MediumType: SubjectiveTopic: Revert
Use `git revert --no-commit A^..B` to stage inverse changes for the range, review, then `git commit` once. Or `git revert A^..B` to create multiple revert commits.
83. Which option reduces the risk when force-pushing rewritten history?
Difficulty: MediumType: MCQTopic: Push Safety
- git push --force
- git push --mirror
- git push --force-with-lease
- git push --atomic
It refuses to overwrite remote work you haven’t fetched, offering a safety check.
Correct Answer: git push --force-with-lease
84. You committed secrets to a private branch and pushed. Outline steps to remove them from history safely.
Difficulty: MediumType: SubjectiveTopic: Scenarios
Rotate the secret. Use `git filter-repo` (or BFG) to purge the file/paths from all commits, force-push with lease, invalidate caches, and update PRs. Add patterns to `.gitignore` to prevent recurrence.
85. What problems do branches solve in Git and how do they enable parallel development?
Difficulty: EasyType: SubjectiveTopic: Branching
Branches isolate work so features, fixes, and experiments can proceed without impacting the main line. They allow concurrent workflows, easier code review via PRs, and controlled integration back to trunk.
86. Which command both creates a new branch and switches to it (modern syntax)?
Difficulty: EasyType: MCQTopic: Branching
- git branch feature/login && git checkout feature/login
- git switch -C feature/login
- git checkout -b feature/login
- git branch -m feature/login
`git switch -C` creates (or resets) and checks out the branch in one step.
Correct Answer: git switch -C feature/login
87. How do you create a local branch that tracks an existing remote branch?
Difficulty: EasyType: SubjectiveTopic: Tracking Branch
Use `git switch -c feature origin/feature` or `git checkout --track origin/feature`. This sets upstream so pulls/pushes use the remote branch by default.
88. When does Git perform a fast-forward merge?
Difficulty: MediumType: MCQTopic: Fast Forward
- When histories have diverged and require a 3-way merge
- When the target branch tip can be moved forward without a merge commit
- Only when merging tags
- Only after rebase
If no divergence exists, Git advances the pointer (no merge commit).
Correct Answer: When the target branch tip can be moved forward without a merge commit
89. Why use `git merge --no-ff` on a feature branch?
Difficulty: MediumType: MCQTopic: No FF
- To enforce a merge commit for clearer feature grouping/history
- To avoid conflicts during merge
- To run CI twice automatically
- To rewrite commit authors
`--no-ff` keeps a merge node even if fast-forward is possible, preserving feature context.
Correct Answer: To enforce a merge commit for clearer feature grouping/history
90. Compare `git merge` and `git rebase` for integrating main into a feature branch. When would you choose each?
Difficulty: MediumType: SubjectiveTopic: Merge Rebase
Merge preserves history with a merge commit—good for shared branches. Rebase rewrites the feature to sit atop main—clean linear history, ideal before opening a PR. Avoid rebasing public branches.
91. Which statement about rebasing is TRUE?
Difficulty: MediumType: MCQTopic: Rebase Safety
- Rebasing a shared remote branch is always safe
- Rebase changes commit hashes and should not be used on already-pushed shared history
- Rebase never causes conflicts
- Rebase adds a merge commit
Rewriting history creates new commits; force-push would be required and can disrupt collaborators.
Correct Answer: Rebase changes commit hashes and should not be used on already-pushed shared history
92. Main has moved ahead. Show two safe ways to bring a feature branch up to date and discuss trade-offs.
Difficulty: MediumType: SubjectiveTopic: PR Workflow
1) `git merge origin/main` → non-destructive, may create merge commits. 2) `git rebase origin/main` → linear history, rewrites commits (avoid if already shared).
93. What does a squash merge do in a PR workflow?
Difficulty: MediumType: MCQTopic: Squash Merge
- Keeps every feature commit and creates a merge commit
- Combines all feature commits into one commit on the target branch
- Deletes the feature branch without merging
- Forces a fast-forward
Squash yields a single commit; good for tidy history, but loses granular commit info.
Correct Answer: Combines all feature commits into one commit on the target branch
94. Outline a practical process to resolve merge conflicts during a rebase.
Difficulty: MediumType: SubjectiveTopic: Conflicts
Run `git rebase main`; when conflict occurs: fix files, `git add <files>`, `git rebase --continue`. Use `git rebase --skip` to drop a commit if appropriate, or `git rebase --abort` to revert.
95. Which command sets the upstream branch so `git pull` knows the remote to track?
Difficulty: EasyType: MCQTopic: Push
- git branch --unset-upstream
- git branch --set-upstream-to=origin/main
- git push --set-upstream origin main
- git remote set-url origin <url>
This ties the current local branch to a remote tracking branch for pull/push defaults.
Correct Answer: git branch --set-upstream-to=origin/main
96. Your team enforces a linear history on main. Propose a branch policy and CLI steps to satisfy it.
Difficulty: MediumType: SubjectiveTopic: Rebase
Policy: feature branches rebase onto latest main; PRs merge with squash or rebase-merge; disallow merge commits on main. Steps: `git fetch`, `git rebase origin/main`, resolve, push with `--force-with-lease`, then squash-merge PR.
97. What is an octopus merge in Git?
Difficulty: HardType: MCQTopic: Advanced Merge
- A merge involving two parents only
- A merge of more than two branches at once
- A rebase of multiple branches together
- A merge that always fast-forwards
Octopus merges combine multiple heads, usually for automated, conflict-free integrations.
Correct Answer: A merge of more than two branches at once
98. Describe a pragmatic branching model for a product team shipping weekly (branches, integration, release).
Difficulty: MediumType: SubjectiveTopic: Git Workflow
Trunk-based or short-lived feature branches; protect `main` with CI; feature toggles for incomplete work; cut `release/*` branch weekly for stabilization; hotfix branches from `main`; merge via PR with squash; tag releases.
99. What problems does `git stash` solve in day-to-day work?
Difficulty: EasyType: SubjectiveTopic: Stash
Stash lets you temporarily shelve uncommitted changes so you can switch branches, pull fixes, or review code with a clean tree. Later you reapply the changes, avoiding throwaway commits or losing work.
100. Which command saves tracked modifications and clears your working tree?
Difficulty: EasyType: MCQTopic: Stash
- git save
- git stash
- git park
- git shelve
`git stash` (or `git stash push`) stores current tracked changes and resets the worktree.
Correct Answer: git stash
101. How do `git stash apply` and `git stash pop` differ?
Difficulty: MediumType: MCQTopic: Stash
- `apply` reapplies changes and keeps the stash; `pop` reapplies and removes the stash entry
- `apply` deletes the stash; `pop` lists stashes
- They are aliases; no difference
- `pop` works only with untracked files
`pop = apply + drop`. Use `apply` to reuse later, `pop` to consume once.
Correct Answer: `apply` reapplies changes and keeps the stash; `pop` reapplies and removes the stash entry
102. Which command stashes tracked and untracked files together?
Difficulty: MediumType: MCQTopic: Stash
- git stash -u
- git stash --keep-index
- git stash --patch
- git stash --staged
`-u/--include-untracked` adds untracked files; use `-a` to include ignored too.
Correct Answer: git stash -u
103. How do you stash tracked, untracked, and ignored files?
Difficulty: MediumType: MCQTopic: Stash
- git stash --all
- git stash --ignored
- git stash -u
- git stash --hard
`--all` (aka `-a`) includes ignored and untracked files along with tracked changes.
Correct Answer: git stash --all
104. What does `git stash --keep-index` do and when is it useful?
Difficulty: MediumType: SubjectiveTopic: Stash
It stashes only unstaged changes while leaving the index intact. Useful before running tests/CI on exactly what is staged for commit without noise from local WIP.
105. How do you add a message to a stash entry?
Difficulty: EasyType: MCQTopic: Stash
- git stash save -m "msg"
- git stash push -m "msg"
- git stash -m "msg"
- git stash commit -m "msg"
Modern syntax uses `git stash push -m "message"` to label the stash.
Correct Answer: git stash push -m "msg"
106. How do you list stash entries and view what changed inside a specific stash?
Difficulty: EasyType: SubjectiveTopic: Git Log
List with `git stash list`. Inspect with `git stash show -p stash@{n}` to see the patch, or `git show stash@{n}` for full object details.
107. You want to stash only parts of files. Which command helps?
Difficulty: MediumType: MCQTopic: Stash
- git stash --partial
- git stash --hunk
- git stash -p
- git stash --split
`-p/--patch` lets you interactively pick hunks to stash.
Correct Answer: git stash -p
108. What does `git clean` do and why is it dangerous?
Difficulty: MediumType: SubjectiveTopic: Clean
`git clean` removes untracked files/dirs from the working tree. It permanently deletes files not tracked by Git, so use `-n` (dry-run) first to preview.
109. Which option pair removes untracked directories as well and bypasses safety prompts?
Difficulty: MediumType: MCQTopic: Clean
`-d` removes untracked directories; `-f` is required to actually perform deletion.
Correct Answer: -f -d
110. How do you clean ignored files (e.g., build artifacts) as well?
Difficulty: MediumType: MCQTopic: Clean
- git clean -fx
- git clean -fu
- git clean -fdn
- git clean --all
`-x` makes `clean` also remove ignored files; pair with `-f` to apply.
Correct Answer: git clean -fx
111. Outline a safe workflow to tidy your working tree before a release cut without losing progress.
Difficulty: MediumType: SubjectiveTopic: Clean
1) Commit or stash WIP (`git stash -p -m "wip"`). 2) Verify status (`git status`, `git stash list`). 3) Clean dry-run (`git clean -ndx`). 4) If OK, run `git clean -fdx` for a pristine tree. 5) Reapply stashed pieces as needed with `git stash apply` and re-stage.
112. Why do teams create branches instead of committing directly to main?
Difficulty: EasyType: SubjectiveTopic: Branching
Branches isolate work (features, fixes, experiments), keep main stable, enable review and CI per branch, and simplify rollback/cleanup without risking production code.
113. Which statement best describes GitHub Flow?
Difficulty: MediumType: MCQTopic: Git Workflow
- Long-lived develop branch; release/hotfix branches
- Trunk-based: short-lived branches from main with PRs and frequent deploys
- Multiple protected environment branches per environment
- No branches; commits go to main directly
GitHub Flow favors small feature branches off main with PR review and continuous delivery.
Correct Answer: Trunk-based: short-lived branches from main with PRs and frequent deploys
114. In classical Git Flow, which branches are long-lived?
Difficulty: MediumType: MCQTopic: Branch Models
- main and feature/*
- develop and release/*
- main and develop
- hotfix/* and release/*
Git Flow uses persistent main and develop branches; feature/release/hotfix are short-lived.
Correct Answer: main and develop
115. Name three common branch protection rules teams enable on main.
Difficulty: MediumType: SubjectiveTopic: Branch Rules
Require PR reviews, require status checks (CI) to pass, disallow force-pushes, require up-to-date with base, enforce signed commits, and restrict who can push.
116. What key elements should a good Pull Request include?
Difficulty: EasyType: SubjectiveTopic: Pull Requests
Clear title, description (problem, approach, scope), links to issues/tickets, screenshots/logs, test notes, checklist, and small, focused commits.
117. When should you open a Draft PR?
Difficulty: EasyType: MCQTopic: Pull Requests
- When code is finished and ready to merge
- To share early work for feedback/CI while signaling it’s not ready to merge
- Only for security fixes
- Never; drafts block CI
Draft PRs invite early review without merge intent.
Correct Answer: To share early work for feedback/CI while signaling it’s not ready to merge
118. What does a CODEOWNERS file typically enforce?
Difficulty: MediumType: MCQTopic: Code Owners
- Auto-assign reviewers and optionally require their approval for specific paths
- Auto-merge PRs after 24 hours
- Prevent non-owners from creating branches
- Lock main after releases
CODEOWNERS maps paths to responsible reviewers and can be required by branch rules.
Correct Answer: Auto-assign reviewers and optionally require their approval for specific paths
119. Why are smaller PRs generally preferred?
Difficulty: MediumType: SubjectiveTopic: PR Best
They’re easier to review, reduce cycle time, lower defect risk, improve merge success, and aid revertability.
120. Which merge method keeps a linear history by replaying commits onto the base branch?
Difficulty: MediumType: MCQTopic: PR Merges
- Create a merge commit
- Squash and merge
- Rebase and merge
- Fast-forward disable
Rebase+merge rewrites branch commits on top of base to keep history linear.
Correct Answer: Rebase and merge
121. A team wants one commit per PR on main. Which setting fits best?
Difficulty: MediumType: MCQTopic: Squash Merge
- Allow merge commits
- Require rebase merges
- Squash and merge
- Force push after merge
Squash condenses all PR commits into one for a tidy history.
Correct Answer: Squash and merge
122. Main has moved since you opened a PR. Compare merging main into your branch vs. rebasing onto main.
Difficulty: MediumType: SubjectiveTopic: PR Workflow
Merging preserves history and is non-destructive but adds merge commits. Rebasing keeps a linear history but rewrites commits and requires force-push to the PR branch.
123. Which PR description phrase auto-closes a GitHub issue on merge?
Difficulty: EasyType: MCQTopic: Pull Requests
- Relates: #123
- Refs #123
- Fixes #123
- Ping #123
Keywords like “Fixes/Closes/Resolves #id” close the issue on merge to default branch.
Correct Answer: Fixes #123
124. List good reviewer behaviors in PRs.
Difficulty: MediumType: SubjectiveTopic: Code Review
Review promptly, be specific and kind, ask clarifying questions, suggest concrete changes, verify tests/docs, pull locally when needed, and approve only after required checks pass.
125. Explain what `git rebase` does in your own words.
Difficulty: MediumType: SubjectiveTopic: Rebase
Rebase replays commits from your branch onto a new base, creating new commit IDs and a linear history. It’s a rewrite; the old commits are replaced by equivalent ones atop the target base.
126. Which is a safe scenario for interactive rebase?
Difficulty: MediumType: MCQTopic: When to Rebase
- On a public, shared main branch
- On your personal feature branch before pushing
- On a protected release branch
- On any branch after merge
Rewrite only private/unpushed history to avoid disrupting collaborators.
Correct Answer: On your personal feature branch before pushing
127. Which action in `git rebase -i` combines commits while preserving both messages?
Difficulty: MediumType: MCQTopic: Rebase
`squash` merges commits and lets you edit a combined message; `fixup` discards the later message.
Correct Answer: squash
128. What are fixup commits and how do `--autosquash` and `--rebase` work together?
Difficulty: MediumType: SubjectiveTopic: Autosquash
Create `fixup! <subject>` commits to mark quick corrections. With `--autosquash`, interactive rebase auto-positions those fixups next to their targets for clean squashing.
129. How do you configure `git pull` to rebase by default for the current repo?
Difficulty: EasyType: MCQTopic: Pull Rebase
- git config --global pull.rebase true
- git config pull.rebase true
- git pull --default=rebase
- git set pull.rebase=true
Set at repo scope with `git config pull.rebase true` (or `--global` for all repos).
Correct Answer: git config pull.rebase true
130. During a rebase with conflicts, which commands are used to proceed or cancel?
Difficulty: EasyType: MCQTopic: Rebase
- `git rebase --proceed` / `git rebase --cancel`
- `git rebase --continue` / `git rebase --abort`
- `git continue` / `git abort`
- `git resolve` / `git reset --hard`
Resolve conflicts, `git add`, then `--continue`; use `--abort` to return to pre-rebase state.
Correct Answer: `git rebase --continue` / `git rebase --abort`
131. When is `git cherry-pick` preferred over merging a whole branch?
Difficulty: MediumType: SubjectiveTopic: Cherry Pick
When you need only specific commits (e.g., a hotfix) without bringing other work, to keep a minimal, controlled change set.
132. Which syntax cherry-picks a range of commits (excluding the lower bound)?
Difficulty: MediumType: MCQTopic: Cherry Pick
- git cherry-pick A..B
- git cherry-pick A...B
- git cherry-pick B..A
- git cherry-pick A^..B^
`A..B` applies commits reachable from B but not A (lower bound exclusive).
Correct Answer: git cherry-pick A..B
133. Which flag adds a Signed-off-by trailer while cherry-picking?
Difficulty: EasyType: MCQTopic: Signed Commits
- --sign
- --gpg-sign
- --signoff
- --author
`--signoff` appends a DCO sign-off line to the commit message.
Correct Answer: --signoff
134. Why is rewriting public history dangerous and how can teams mitigate the risk?
Difficulty: MediumType: SubjectiveTopic: Rewrite Safety
Rewrites change commit IDs, breaking collaborators’ history and remotes. Mitigate with protected branches, disallowing force-push, using merge on shared branches, and rewriting only private branches.
135. You rewrote history and lost commits locally. How can `reflog` help?
Difficulty: MediumType: SubjectiveTopic: Reflog
`git reflog` shows previous HEAD positions. Identify the lost commit or pre-rebase state and `git reset --hard <hash>` or create a new branch from it to recover.
136. Which sequence correctly cleans up WIP using autosquash?
Difficulty: MediumType: MCQTopic: Autosquash
- Create fixup commits → git rebase -i --autosquash base
- git rebase --merge → fixup commits → push
- git squash --auto → push --force
- git rebase --continue --autosquash
Tag fixups (`fixup! subject`) then run interactive rebase with `--autosquash`.
Correct Answer: Create fixup commits → git rebase -i --autosquash base
137. Why do teams create Git tags and when are annotated tags preferred over lightweight tags?
Difficulty: EasyType: SubjectiveTopic: Tags
Tags mark important points in history (e.g., releases). Annotated tags store metadata (tagger, date, message, signature) and are ideal for official releases; lightweight tags are simple pointers for personal bookmarks.
138. Which command creates an annotated tag named v1.2.0 with a message?
Difficulty: EasyType: MCQTopic: Tags
- git tag v1.2.0 -m "Release 1.2.0"
- git tag -a v1.2.0 -m "Release 1.2.0"
- git tag --annotate "Release 1.2.0" v1.2.0
- git annotate -t v1.2.0 "Release 1.2.0"
`-a` creates an annotated tag and `-m` sets its message.
Correct Answer: git tag -a v1.2.0 -m "Release 1.2.0"
139. How do you push a single tag named v2.0.0 to origin?
Difficulty: MediumType: MCQTopic: Tags
- git push origin --tags
- git push origin :tags v2.0.0
- git push origin tag v2.0.0
- git push origin v2.0.0
Pushing a specific tag uses `git push <remote> <tag>`; `--tags` pushes all tags.
Correct Answer: git push origin v2.0.0
140. Which pair correctly deletes a remote tag v1.0.0 from origin after deleting it locally?
Difficulty: MediumType: MCQTopic: Tags
- git tag -d v1.0.0; git push origin :refs/tags/v1.0.0
- git tag --remove v1.0.0; git push origin --delete tag v1.0.0
- git tag -D v1.0.0; git push origin --delete v1.0.0
- git rm tag v1.0.0; git push origin --prune tags
Local delete with `git tag -d`; remote delete with a push of an empty ref to the tag.
Correct Answer: git tag -d v1.0.0; git push origin :refs/tags/v1.0.0
141. In Semantic Versioning MAJOR.MINOR.PATCH, which increment signals backward-incompatible changes?
Difficulty: EasyType: MCQTopic: SemVer
MAJOR → incompatible, MINOR → new compatible features, PATCH → bug fixes.
Correct Answer: MAJOR
142. Which is a valid SemVer pre-release tag?
Difficulty: MediumType: MCQTopic: SemVer
- 2.1.0-preview+001
- v2.1.0-preview.1 (with leading v inside SemVer core)
- 2.1-preview.1.0
- 2.1.0#rc1
Valid format: MAJOR.MINOR.PATCH-PRERELEASE+BUILD; leading 'v' is not part of SemVer core.
Correct Answer: 2.1.0-preview+001
143. What should high-quality release notes include for a tagged release?
Difficulty: MediumType: SubjectiveTopic: Releases
Highlights, breaking changes, migration steps, bug fixes, known issues, contributors, and links to diffs/PRs. Keep crisp and user-centric.
144. Which command creates a GPG-signed tag?
Difficulty: MediumType: MCQTopic: Tags
- git tag -g v3.0.0 -m "signed"
- git tag -s v3.0.0 -m "Release 3.0.0"
- git tag --secure v3.0.0
- git sign tag v3.0.0
`-s` signs the tag with your configured GPG key for provenance.
Correct Answer: git tag -s v3.0.0 -m "Release 3.0.0"
145. How would you design a tagging strategy for a service with weekly releases, hotfixes, and experimental builds?
Difficulty: MediumType: SubjectiveTopic: Tags
Use SemVer for GA (e.g., vX.Y.Z), suffix `-rc.N`/`-beta.N` for candidates, `-hotfix.N` for urgent patches, and build metadata for CI artifacts. Protect tags, sign GA tags, auto-generate notes via CI.
146. Which command lists commits between tags v1.1.0 (exclusive) and v1.2.0 (inclusive) on current branch?
Difficulty: MediumType: MCQTopic: Git Log
- git log v1.1.0..v1.2.0
- git log v1.1.0...v1.2.0
- git diff v1.1.0...v1.2.0
- git show v1.1.0..v1.2.0 --oneline
`A..B` shows commits reachable from B and not A; `...` is symmetric difference.
Correct Answer: git log v1.1.0..v1.2.0
147. How do Git hosting releases relate to Git tags, and what extras do they provide?
Difficulty: EasyType: SubjectiveTopic: Releases
A release is metadata built around a tag: rich notes, attachments (artifacts), checksums, and visibility controls—useful for distributing binaries and changelogs.
148. You want CI to cut a PATCH release on every merged hotfix PR. Which approach is most appropriate?
Difficulty: MediumType: MCQTopic: Tags
- Generate random tag names on each build
- Bump SemVer via a changelog/conventional commits and create annotated tags from CI on main
- Force-push tags from feature branches
- Create lightweight tags on each commit in all branches
Automate SemVer bumps on protected branch and create annotated (optionally signed) tags with release notes.
Correct Answer: Bump SemVer via a changelog/conventional commits and create annotated tags from CI on main
149. Which command shows the most recent tag reachable from HEAD?
Difficulty: EasyType: MCQTopic: Tags
- git tag --latest
- git describe --tags --abbrev=0
- git show --last-tag
- git latest-tag
`git describe` finds the nearest tag; `--abbrev=0` prints only the tag name.
Correct Answer: git describe --tags --abbrev=0
150. When would you choose GitHub Flow over Git Flow for a team, and why?
Difficulty: MediumType: SubjectiveTopic: Git Workflow
GitHub Flow (trunk-based: small feature branches → PR → merge to main → deploy) fits products that deploy very frequently and value simplicity. Git Flow (long-lived develop, release/hotfix branches) suits scheduled releases and heavier QA gates. Choose the simplest model that matches release cadence and compliance needs.
151. Which settings best protect the main branch in a collaborative repo?
Difficulty: EasyType: MCQTopic: Branch Rules
- Allow force pushes and direct commits to main
- Require PR reviews, status checks, and disallow force pushes
- Disable PRs and merge everything locally
- Turn off CI to speed up merges
Branch protection with mandatory reviews and passing CI prevents broken code and history rewrites.
Correct Answer: Require PR reviews, status checks, and disallow force pushes
152. Which commit message follows a widely adopted conventional style?
Difficulty: EasyType: MCQTopic: Commit Hygiene
- fix: handle null in user serializer
- changed some stuff
- WIP
- final commit
Conventional Commits use type(scope?): subject — e.g., feat, fix, chore, docs — aiding automation and changelogs.
Correct Answer: fix: handle null in user serializer
153. A PR has many 'merge from main' commits. Reviewers ask to clean it up. What do you do and why?
Difficulty: MediumType: SubjectiveTopic: Merge Policy
Interactively rebase the feature branch onto the latest main and squash noisy merges into logical commits. This yields a linear, readable history while preserving meaningful changes. Avoid rewriting history only after the branch is shared publicly unless teammates agree.
154. What is the purpose of a CODEOWNERS file?
Difficulty: MediumType: MCQTopic: Code Owners
- Stores repository secrets
- Defines default reviewers/approvers for paths
- Caches dependency versions
- Configures Git on developer machines
CODEOWNERS maps file globs to teams/users, auto-requesting reviews and enforcing approvals.
Correct Answer: Defines default reviewers/approvers for paths
155. List three characteristics of an effective pull request review.
Difficulty: EasyType: SubjectiveTopic: Code Review
Actionable comments (specific, respectful), checks for correctness & security, and validation via passing CI/tests. Keep scope focused, request changes with rationale, and approve only when standards are met.
156. Why prefer small, focused PRs?
Difficulty: EasyType: MCQTopic: PR Best
- They reduce review time and risk, and speed feedback loops
- They hide changes from auditors
- They guarantee zero conflicts
- They eliminate the need for tests
Smaller diffs are easier to review thoroughly and roll back when needed.
Correct Answer: They reduce review time and risk, and speed feedback loops
157. A good pull request template typically includes:
Difficulty: MediumType: MCQTopic: Pull Requests
- Feature description, test plan, screenshots/logs, risk/rollback
- Only a meme
- The entire app binary
- Sensitive credentials for reviewers
Structured context improves review quality and deploy safety.
Correct Answer: Feature description, test plan, screenshots/logs, risk/rollback
158. How should you respond when you disagree with a reviewer’s suggestion?
Difficulty: EasyType: SubjectiveTopic: Code Review
Acknowledge the concern, provide evidence (benchmarks, standards), seek compromise, or escalate to documented guidelines/architects. Never ignore feedback; document the decision in the PR for future readers.
159. In a monorepo with many services, which practice helps avoid breaking dependents?
Difficulty: MediumType: MCQTopic: Monorepo Coordination
- Force-push after every commit
- Use CI to run affected-graph tests and require green checks before merge
- Disable tests to speed merges
- Commit directly to main frequently without reviews
Change impact analysis plus mandatory checks protects downstream packages.
Correct Answer: Use CI to run affected-graph tests and require green checks before merge
160. What is one proven tactic to reduce back-and-forth in reviews?
Difficulty: EasyType: MCQTopic: Code Review
- Submit one 5,000-line PR
- Pair program or conduct pre-PR design review
- Avoid writing a description
- Merge without approval
Early collaboration reduces rework and aligns on approach.
Correct Answer: Pair program or conduct pre-PR design review
161. Which checklist item is BEST for security during code review?
Difficulty: MediumType: MCQTopic: Code Review
- Ensure no TODO comments exist
- Validate input/output, secrets not committed, and dependency changes scanned
- Rename all variables to short names
- Skip third-party changes
Threat-aware review plus automated secret scanning and SCA improves security posture.
Correct Answer: Validate input/output, secrets not committed, and dependency changes scanned
162. When would you enforce squash merging in a repository and what are the trade-offs?
Difficulty: MediumType: SubjectiveTopic: PR Merges
Enforce squash to keep a clean, one-commit-per-PR history and easy revert. Trade-offs: lose granular interim commits and bisect fidelity; mitigate by writing a thorough squash message and linking PR.
163. You want to nudge developers to submit smaller PRs. What’s a practical step?
Difficulty: MediumType: MCQTopic: PR Best
- Block all PRs over 50 lines
- Add a CI warning or soft gate on changed-lines with guidance and examples
- Delete large PRs without comment
- Require three architects to approve any PR
Gentle automation plus education shapes behavior without stalling delivery.
Correct Answer: Add a CI warning or soft gate on changed-lines with guidance and examples