Git & Version Control MCQ
Test your Git & Version Control knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
How This Practice Test Works
Every question below expands right on this page — click a question to reveal its four options, pick the one you think is correct, and you'll get instant feedback along with the correct answer and a short explanation of the reasoning. Questions are grouped by difficulty, so start with the 40 beginner questions to confirm your fundamentals, work through the 40 intermediate ones, and finish with the 20 advanced questions that mirror what exams and technical screenings actually ask. There's no sign-up, no timer, and no limit — retake the test as often as you like.
Curated by Tech Baithak Editorial Team · Last updated: June 2026
1
What is Git?
Correct Answer
A distributed version control system for tracking changes in source code
Explanation
Git is a distributed version control system that tracks changes to files over time, allowing multiple people to collaborate on a project and revert to previous states if needed.
2
What does the "git init" command do?
Correct Answer
Initializes a new, empty Git repository in the current directory
Explanation
"git init" creates a new ".git" subdirectory in the current folder, turning it into a Git repository that can begin tracking file changes.
3
What is a "repository" (repo) in Git?
Correct Answer
A storage location containing a project's files along with the complete history of changes made to them
Explanation
A Git repository contains both the project's files and a complete, versioned history of all changes (commits) made to them, stored in a hidden ".git" directory.
4
What does the "git clone" command do?
Correct Answer
Creates a local copy of a remote repository, including its full history
Explanation
"git clone <url>" downloads a complete copy of a remote repository, including all its commits, branches, and tags, to the local machine.
5
What is the purpose of "git add"?
Correct Answer
It stages changes (new, modified, or deleted files), preparing them to be included in the next commit
Explanation
"git add <file>" moves changes from the working directory to the staging area (index), marking them to be included in the next "git commit".
6
What does "git commit" do?
Correct Answer
It records the staged changes as a new snapshot in the repository's history, along with a descriptive message
Explanation
"git commit -m \"message\"" saves a permanent snapshot of the staged changes to the local repository's history, identified by a unique commit hash.
7
What is the "working directory" in Git?
Correct Answer
The directory on your local filesystem containing the actual project files you are currently editing
Explanation
The working directory is where you see and edit your project's files; changes here are "untracked" or "modified" until staged with "git add" and committed.
8
What is the "staging area" (also called the "index") in Git?
Correct Answer
An intermediate area where changes are placed before being committed, allowing you to selectively prepare what goes into the next commit
Explanation
The staging area lets you build up a commit incrementally — you can stage some changes with "git add" while leaving others unstaged, giving fine-grained control over what each commit contains.
9
What does the "git status" command show?
Correct Answer
The current state of the working directory and staging area, including which files are modified, staged, or untracked
Explanation
"git status" gives an overview of your repo's current state — which branch you're on, and which files are staged, modified, or untracked.
10
What does "git log" display?
Correct Answer
The commit history of the current branch, showing commit hashes, authors, dates, and messages
Explanation
"git log" shows a chronological list of commits on the current branch, each with its unique hash, author, date, and commit message.
11
What is a "branch" in Git?
Correct Answer
A movable pointer to a specific commit, representing an independent line of development
Explanation
A branch is essentially a lightweight, movable pointer to a commit, allowing development to diverge from the main line of work without affecting it until merged.
12
What is the default branch name commonly used in new Git repositories today?
Correct Answer
"main" (previously "master" was the traditional default)
Explanation
Many platforms and Git versions now default to naming the initial branch "main" instead of the historically used "master", though both can be configured.
13
What command creates a new branch named "feature-x"?
Correct Answer
git branch feature-x
Explanation
"git branch <name>" creates a new branch pointer at the current commit, but does not switch to it; "git checkout -b <name>" or "git switch -c <name>" both create and switch to it in one step.
14
What does "git checkout <branch>" (or "git switch <branch>") do?
Correct Answer
Switches the working directory to reflect the specified branch, updating tracked files accordingly
Explanation
Checking out (or switching to) a branch updates the working directory's files to match the tip of that branch and moves HEAD to point to it.
15
What is "HEAD" in Git?
Correct Answer
A reference that points to the current commit/branch you have checked out — essentially "where you currently are"
Explanation
HEAD is a pointer that usually points to the latest commit of the currently checked-out branch; it moves automatically as you make new commits or switch branches.
16
What does "git pull" do?
Correct Answer
It fetches changes from a remote repository and merges them into the current local branch
Explanation
"git pull" is essentially a combination of "git fetch" (downloading new data) followed by "git merge" (integrating that data into the current branch).
17
What does "git push" do?
Correct Answer
It uploads local commits from the current branch to a remote repository
Explanation
"git push" sends locally committed changes to a remote repository, updating the corresponding remote branch so others can see your work.
18
What is a "remote" in Git, e.g. "origin"?
Correct Answer
A reference to a version of the repository hosted elsewhere (e.g. on GitHub, GitLab), used for sharing and collaboration
Explanation
"origin" is the conventional name given to the remote repository a local repo was cloned from; remotes let you sync changes between local and hosted copies of a repository.
19
What is the purpose of a ".gitignore" file?
Correct Answer
It lists files and directories that Git should ignore and not track (e.g. build artifacts, dependency folders, log files)
Explanation
".gitignore" specifies patterns for files/directories (like "node_modules/" or "*.log") that Git should never track or show as untracked, keeping the repository clean.
20
What is a "merge conflict"?
Correct Answer
An error that occurs when Git cannot automatically combine changes from two branches because they modified the same part of a file in different ways
Explanation
A merge conflict arises when two branches have divergent changes to the same lines of a file, requiring a human to manually decide how to resolve the differences before the merge can complete.
21
What does "git merge" do?
Correct Answer
It combines the changes from one branch into another, creating a new merge commit if the histories have diverged
Explanation
"git merge <branch>" integrates the changes from the named branch into the current branch, typically creating a merge commit that has two parent commits.
22
What is the difference between "git fetch" and "git pull"?
Correct Answer
"git fetch" downloads changes from a remote without modifying the working directory or current branch, while "git pull" downloads AND immediately merges those changes into the current branch
Explanation
"git fetch" is a safer way to see what changes exist on the remote without altering your current work, since it doesn't merge anything until you explicitly do so.
23
What is a "commit hash" (or SHA)?
Correct Answer
A unique identifier (a long hexadecimal string) generated for each commit, based on its content and metadata
Explanation
Each commit is identified by a SHA-1 hash computed from its content, parent(s), author, and message, ensuring that even a tiny change produces a completely different hash.
24
What does the "git diff" command show?
Correct Answer
The differences between the working directory, staging area, and/or commits, showing exactly what lines were added or removed
Explanation
"git diff" displays line-by-line changes (additions and deletions) between different states, such as working directory vs. staging area, or between two commits.
25
What is the purpose of "git rm"?
Correct Answer
It removes a file from both the working directory and stages the deletion for the next commit
Explanation
"git rm <file>" deletes the file from the working directory and stages that removal, so the deletion will be recorded in the next commit.
26
What does "git config" allow you to do?
Correct Answer
Set configuration values such as user name, email, default editor, and various Git behavior options
Explanation
"git config" sets values like "user.name" and "user.email" (used to attribute commits) and other settings, at global (per-user) or local (per-repo) scope.
27
What is the difference between "git config --global" and "git config" (local)?
Correct Answer
"--global" applies the setting to all repositories for the current user, while a local config setting applies only to the current repository
Explanation
Global config (stored in ~/.gitconfig) applies as a default across all repositories for that user, while local config (stored in .git/config) overrides it for a specific repository.
28
What is GitHub (or GitLab/Bitbucket) in relation to Git?
Correct Answer
A web-based hosting service for Git repositories, providing collaboration features like pull requests, issue tracking, and code review on top of Git
Explanation
Git itself is the underlying version control tool, while GitHub, GitLab, and Bitbucket are separate hosting platforms that add web interfaces, collaboration tools, and CI/CD integrations around Git repositories.
29
What is a "pull request" (PR) or "merge request" (MR)?
Correct Answer
A proposal to merge changes from one branch (often a feature branch) into another (often the main branch), allowing for review and discussion before merging
Explanation
PRs/MRs are a feature of hosting platforms (not Git itself) that let team members review, comment on, and discuss proposed changes before they are merged into a target branch.
30
What does "git revert <commit>" do?
Correct Answer
It creates a new commit that undoes the changes introduced by the specified commit, while preserving history
Explanation
"git revert" is a safe way to undo a commit's changes — instead of rewriting history, it adds a new commit that applies the inverse of the original changes.
31
What is the purpose of "git tag"?
Correct Answer
To mark specific points in history as important, typically used for marking release versions (e.g. v1.0.0)
Explanation
Tags are references that point to specific commits, commonly used to mark release points like "v1.0.0"; unlike branches, tags don't move as new commits are made.
32
What is the meaning of "untracked" files in "git status" output?
Correct Answer
New files in the working directory that Git has not yet been told to track (have never been staged/committed)
Explanation
Untracked files exist in the working directory but Git is not yet monitoring changes to them; running "git add" begins tracking them.
33
What is the purpose of the "README" file commonly found in repositories?
Correct Answer
A documentation file (often in Markdown) that introduces the project, explaining what it does and how to use or contribute to it
Explanation
A README is typically the first file visitors see on a repository's homepage (e.g. on GitHub), providing an overview, setup instructions, and usage documentation for the project.
34
What does "git branch" (with no arguments) display?
Correct Answer
A list of all local branches, with the current branch highlighted/marked
Explanation
Running "git branch" without arguments lists all local branches, with an asterisk (*) typically indicating the currently checked-out branch.
35
What is the purpose of "git show <commit>"?
Correct Answer
It displays detailed information about a specific commit, including its metadata and the changes it introduced
Explanation
"git show <commit-hash>" displays the commit's message, author, date, and the diff of changes introduced by that commit.
36
What is the purpose of "git clone --depth 1"?
Correct Answer
It clones only the most recent commit (a "shallow" clone), reducing download size and time for large repositories
Explanation
A shallow clone (--depth 1) downloads only the latest snapshot of the repository without its full history, which is useful when full history isn't needed, such as in CI pipelines.
37
What is the typical first step before making changes to a shared project hosted on GitHub that you don't have write access to?
Correct Answer
Create a personal copy of the repository ("fork") under your own account, then clone your fork to work on it
Explanation
Forking creates your own copy of someone else's repository on the hosting platform; you can freely make changes there and later propose them back to the original via a pull request.
38
What does the "git mv" command do?
Correct Answer
It renames or moves a file and stages that change for the next commit, in a single step
Explanation
"git mv old_name new_name" is a convenience command equivalent to running "mv" and then "git add" for both the old (removed) and new paths, staging the rename in one step.
39
What is the purpose of the "-m" flag in "git commit -m 'message'"?
Correct Answer
It allows the commit message to be specified directly on the command line, instead of opening a text editor
Explanation
Without "-m", "git commit" opens the configured text editor for writing a commit message; "-m 'message'" provides it inline, which is convenient for short, single-line messages.
40
What does it mean when "git status" reports a file as "modified"?
Correct Answer
The file is tracked by Git, and its content in the working directory differs from the version in the index or last commit
Explanation
A "modified" status means Git is already tracking the file, but you've made changes since the last time it was staged or committed; running "git add" stages those changes.
1
What is the difference between "git merge" and "git rebase" when integrating changes from one branch into another?
Correct Answer
"git merge" combines histories with a new two-parent merge commit, preserving the exact history of both branches, while "git rebase" rewrites the current branch's commits onto the target branch, producing a linear history with no merge commit
Explanation
Rebasing creates a cleaner, linear history by replaying commits onto a new base, but it rewrites commit hashes — which is risky on shared/public branches since it changes history that others may have based work on.
2
What does "git stash" do?
Correct Answer
It temporarily saves uncommitted changes (both staged and unstaged) and reverts the working directory to match HEAD, allowing you to switch contexts and later reapply those changes
Explanation
"git stash" is useful when you need to switch branches quickly without committing half-finished work; "git stash pop" or "git stash apply" later restores the stashed changes.
3
What is the purpose of "git cherry-pick <commit>"?
Correct Answer
It applies the changes introduced by a specific commit from one branch onto the current branch, creating a new commit with those changes
Explanation
Cherry-picking is useful for selectively applying a single commit's changes (e.g. a bugfix) to another branch without merging the entire source branch.
4
What is the difference between "git reset --soft", "git reset --mixed" (default), and "git reset --hard"?
Correct Answer
"--soft" moves HEAD to the target commit but leaves staging and working directory unchanged; "--mixed" (default) also resets staging (changes become unstaged but stay in the directory); "--hard" additionally discards working directory changes
Explanation
Understanding these levels is critical: "--hard" is destructive and discards uncommitted work, while "--soft" is the safest, simply moving the branch pointer while keeping all changes staged.
5
What is a "detached HEAD" state in Git?
Correct Answer
A state where HEAD points directly to a specific commit rather than to a branch, meaning new commits made won't belong to any branch unless one is created
Explanation
You enter detached HEAD by checking out a specific commit (rather than a branch); any new commits made here can be "lost" (become unreachable) unless you create a branch to retain them.
6
What is the purpose of "git blame <file>"?
Correct Answer
It shows, line by line, which commit and author last modified each line of the file, useful for tracking down when and why a change was made
Explanation
"git blame" annotates each line of a file with the commit hash, author, and date of its most recent change, helping trace the origin of specific code.
7
What is the difference between a "fast-forward merge" and a "three-way merge"?
Correct Answer
A fast-forward merge happens when the target branch's pointer can simply move to the source commit via a direct linear path, while a three-way merge is needed when both branches diverged, requiring a new commit combining changes from both
Explanation
When no merge commit is needed (fast-forward), the branch pointer simply advances; "git merge --no-ff" can force a merge commit even when a fast-forward would otherwise be possible, preserving feature-branch context in history.
8
What does "git rebase -i" (interactive rebase) allow you to do?
Correct Answer
It allows you to edit, reorder, squash (combine), split, or drop commits before they are applied onto a new base, giving fine-grained control over commit history
Explanation
Interactive rebase opens an editor listing commits with actions (pick, squash, edit, drop, etc.) that you can modify, commonly used to clean up commit history before merging a feature branch.
9
What does "squashing" commits mean in the context of Git?
Correct Answer
Combining multiple commits into a single commit, typically to create a cleaner, more meaningful history before merging
Explanation
Squashing is often done via interactive rebase ("squash" or "fixup" actions) to combine many small "work in progress" commits into one coherent commit before merging into a shared branch.
10
What is the purpose of "git remote -v"?
Correct Answer
It lists all configured remote repositories along with their fetch and push URLs
Explanation
"git remote -v" (verbose) shows the names (e.g. "origin") and corresponding URLs for fetch and push operations of all remotes configured for the repository.
11
What is a "fork" vs. a "clone" on a platform like GitHub?
Correct Answer
A fork is a server-side copy of a repository created under your own account on the hosting platform, while a clone is a local copy of any repository (forked or not) downloaded to your machine — you typically fork first, then clone your fork
Explanation
Forking is a platform feature (not a core Git command) that creates an independent, server-hosted copy you control, useful for contributing to projects you don't have write access to.
12
What is the purpose of "upstream" tracking branches, e.g. when you see "Your branch is up to date with 'origin/main'"?
Correct Answer
A tracking branch establishes a link between a local branch and a remote branch, allowing commands like "git pull" and "git push" to know which remote branch to sync with by default, and enabling Git to report how far ahead/behind the branches are
Explanation
"git push -u origin <branch>" sets up tracking, so future "git pull"/"git push" on that branch don't require specifying the remote and branch name explicitly.
13
What is the purpose of "git log --graph --oneline --all"?
Correct Answer
It displays a compact, ASCII-art visualization of the commit history across all branches, showing how branches diverged and merged
Explanation
This combination is a popular way to visualize branch and merge structure directly in the terminal: "--graph" draws lines between commits, "--oneline" condenses each commit to one line, and "--all" includes all refs.
14
What is the difference between annotated tags and lightweight tags in Git?
Correct Answer
Annotated tags are stored as full objects in the Git database with metadata (tagger name, date, message, and optionally a GPG signature), while lightweight tags are simply a name pointing to a commit with no additional metadata
Explanation
Annotated tags (created with "git tag -a") are recommended for releases since they store extra information like the tagger and date, and can be cryptographically signed, unlike lightweight tags (created with "git tag").
15
What does the ".git" directory contain?
Correct Answer
All the metadata and object database for the repository, including commits, branches, tags, configuration, and the staging area — essentially everything Git needs to manage version history
Explanation
The ".git" folder is the actual repository — it contains the object database (commits, trees, blobs), refs (branches/tags), HEAD, config, and index (staging area); deleting it removes all version history.
16
What is the purpose of "git reflog"?
Correct Answer
It records a log of where HEAD and branch references have pointed over time, even for commits that are no longer referenced by any branch — useful for recovering "lost" commits after a hard reset or rebase
Explanation
"git reflog" can be a lifesaver after an accidental "git reset --hard" or rebase, since it tracks recent HEAD movements and can help you find and recover commits that seem to have "disappeared".
17
What is the purpose of "git bisect"?
Correct Answer
It uses binary search through commit history to help identify which specific commit introduced a bug, by marking commits as "good" or "bad"
Explanation
"git bisect start" begins a binary search: you mark known good and bad commits, and Git checks out commits in between, narrowing down the exact commit that introduced a regression.
18
What does "git push --force" (or "-f") do, and why is it considered risky?
Correct Answer
It overwrites the remote branch's history with the local branch's history, even if they have diverged — risky because it can permanently discard commits that others have already pushed or based work on
Explanation
Force-pushing rewrites the remote history, which can cause collaborators to lose work or encounter confusing errors; "--force-with-lease" is a safer alternative that fails if the remote has changes you don't have locally.
19
What is a "merge strategy" like "ours" or "recursive" used for in Git?
Correct Answer
Merge strategies determine the algorithm Git uses to combine branches; "recursive" (default for two branches) handles renames and conflicts, while "ours" keeps the current branch's version of conflicting content, ignoring the other side's changes
Explanation
Different merge strategies provide flexibility for special cases — "ours" is sometimes used intentionally to "merge" a branch while discarding its actual content changes, recording history without applying them.
20
What is the purpose of "git submodule"?
Correct Answer
It allows one Git repository to be embedded as a subdirectory of another repository, while keeping the embedded repository's history and commits separate and independently trackable
Explanation
Submodules let a project depend on a specific commit of another repository (e.g. a shared library), but they have a reputation for being tricky to use correctly, particularly around updating and cloning.
21
What is the difference between "origin/main" and "main" as seen in "git branch -a" output?
Correct Answer
"main" refers to the local branch, while "origin/main" is a local reference (remote-tracking branch) representing the state of the "main" branch on the "origin" remote as of the last fetch — they can diverge if either side gets new commits
Explanation
Remote-tracking branches (like "origin/main") are read-only local bookmarks updated by "git fetch"/"git pull" — they reflect the remote's state at the time of the last fetch, not necessarily its current state.
22
What does "git commit --amend" do?
Correct Answer
It modifies the most recent commit, allowing you to change its message and/or add additional staged changes to it, effectively replacing it with a new commit
Explanation
"git commit --amend" is useful for fixing a typo in the last commit message or adding a forgotten file, but it creates a new commit hash, so amending commits already pushed to a shared branch can cause issues for collaborators.
23
What is the purpose of "git clean"?
Correct Answer
It removes untracked files (and optionally directories) from the working directory, which "git status" would list as untracked
Explanation
"git clean -fd" forcibly removes untracked files and directories — useful for clearing build artifacts, but it permanently deletes files not tracked by Git, so it should be used with care (often after a "git clean -n" dry run).
24
What is the significance of the "Conventional Commits" specification (e.g. "feat:", "fix:", "chore:" prefixes)?
Correct Answer
It is a lightweight convention for structuring commit messages in a consistent, machine-readable format that describes the type and scope of a change, often used to automate changelog generation and semantic versioning
Explanation
Conventional Commits is a community convention (not enforced by Git itself, though tools/hooks can enforce it) where prefixes like "feat:" (new feature) or "fix:" (bug fix) help tools automatically determine version bumps and generate release notes.
25
What does "git log --follow <file>" do that plain "git log <file>" might not?
Correct Answer
It shows the commit history of a file including commits from before the file was renamed or moved, by tracking renames
Explanation
Without "--follow", Git's history for a file typically stops at the point it was renamed, since Git doesn't explicitly store rename information — "--follow" attempts to detect renames and continue tracing history through them.
26
What is the purpose of a "pre-commit hook" in Git?
Correct Answer
A script stored in ".git/hooks/" that runs automatically before a commit is finalized, often used to run linters, tests, or formatting checks, and can abort the commit if it fails
Explanation
Git hooks are local scripts triggered by specific Git events; a pre-commit hook can enforce code quality standards by running checks and preventing the commit if they fail, though hooks themselves are not version-controlled by default (tools like Husky help manage this).
27
What happens when you run "git checkout -- <file>" (or "git restore <file>")?
Correct Answer
It discards uncommitted changes to the specified file in the working directory, reverting it to match the version in the index (staging area) or last commit
Explanation
This command discards local, unstaged modifications to a file — a potentially destructive operation since those changes cannot be recovered afterward, unlike staged or committed changes.
28
What is the purpose of "git diff --staged" (or "--cached")?
Correct Answer
It shows the differences between the staging area (index) and the last commit (HEAD), i.e. what would be included if you ran "git commit" right now
Explanation
Plain "git diff" shows unstaged changes (working directory vs. index), while "git diff --staged" shows staged changes (index vs. HEAD) — useful for reviewing exactly what will be committed.
29
What does it mean for a Git branch to have "diverged" from its remote tracking branch?
Correct Answer
Both the local branch and the remote branch have new commits that the other doesn't have, meaning neither is simply ahead or behind the other — a merge or rebase will be needed to reconcile them
Explanation
When branches diverge (each has unique commits the other lacks), a simple fast-forward isn't possible — "git pull" would perform a merge (or rebase, depending on configuration) to combine the divergent histories.
30
What is the purpose of "git worktree"?
Correct Answer
It allows multiple working directories to be checked out from the same repository simultaneously, each on a different branch, without needing separate clones
Explanation
"git worktree add <path> <branch>" creates an additional working directory linked to the same repository, useful for working on multiple branches simultaneously (e.g. testing a hotfix while a feature is in progress) without stashing or cloning.
31
What is the difference between "git fetch --all" and "git fetch origin"?
Correct Answer
"git fetch --all" fetches updates from all configured remotes, while "git fetch origin" (or just "git fetch" with a single remote) only fetches from the remote named "origin"
Explanation
Most repositories only have one remote ("origin"), so the two commands behave the same in that case, but "--all" becomes meaningful when multiple remotes (e.g. "origin" and "upstream") are configured.
32
What is the significance of "merge commits" having two (or more) "parent" commits?
Correct Answer
A merge commit records the point where two (or more) divergent lines of development were combined, with each parent representing the tip of one of the branches being merged — this preserves the full history of how the branches evolved before joining
Explanation
A normal commit has one parent (the previous commit), but a merge commit has two or more, reflecting that it combines changes from multiple branch histories into one — this is what gives merge commits their characteristic appearance in "git log --graph".
33
What is the purpose of using "SSH keys" for authenticating with GitHub instead of HTTPS with a password?
Correct Answer
SSH keys provide a secure, password-less authentication method using a public/private key pair, where the public key is registered with GitHub and the private key on your machine proves your identity for git operations like push and pull
Explanation
Once an SSH key is added to your GitHub account and the remote URL uses the "git@github.com:..." SSH format, Git operations authenticate automatically using the key pair without repeatedly prompting for credentials.
34
What is the purpose of "git diff branch1...branch2" (three dots) versus "git diff branch1..branch2" (two dots)?
Correct Answer
The three-dot form shows changes introduced on "branch2" since it diverged from "branch1" (relative to their merge base), while the two-dot form shows a direct diff between the current tips of the two branches, including changes from both sides
Explanation
The three-dot syntax is often more useful for reviewing "what does this feature branch add" since it isolates changes unique to one side relative to their common ancestor, ignoring unrelated changes that happened on the other branch.
35
What is the purpose of "git stash branch <branchname>"?
Correct Answer
It creates a new branch from the commit where the stash was created, checks it out, and applies the stashed changes there, dropping the stash if successful
Explanation
This is useful when applying a stash directly would cause conflicts due to changes made since stashing — creating a fresh branch from the original commit avoids those conflicts entirely.
36
What is the difference between "git branch -d" and "git branch -D"?
Correct Answer
"-d" (lowercase) deletes a branch only if it has been fully merged into its upstream branch, refusing to delete it otherwise, while "-D" (uppercase) forces deletion regardless of merge status, potentially losing unmerged commits
Explanation
The lowercase "-d" acts as a safety check, preventing accidental loss of commits that exist only on the branch being deleted; "-D" bypasses this check entirely.
37
What does "git log --since='2 weeks ago' --author='Jane'" do?
Correct Answer
It filters the commit history to show only commits made by an author matching "Jane" within the last two weeks
Explanation
"git log" supports many filtering options, including date ranges ("--since", "--until") and author matching ("--author"), useful for auditing recent contributions from specific team members.
38
What is the purpose of "git add -p" (patch mode)?
Correct Answer
It interactively walks through changes in modified files hunk by hunk, allowing you to choose which specific portions of a file's changes to stage, rather than staging the entire file at once
Explanation
Patch mode is useful for splitting a set of unrelated changes within the same file into separate, logically-focused commits, by selectively staging only some of the changed "hunks" at a time.
39
What is the significance of a "protected branch" on platforms like GitHub?
Correct Answer
A protected branch (often the main/production branch) has rules enforced by the hosting platform, such as requiring pull request reviews, passing status checks, or preventing force-pushes and direct pushes, before changes can be merged
Explanation
Branch protection rules are a hosting-platform feature (GitHub, GitLab, etc.) layered on top of Git, used to enforce team workflows like mandatory code review before merging into important branches.
40
What does the term "CI/CD" mean in the context of a Git-based workflow, and how do platforms typically trigger it?
Correct Answer
"Continuous Integration/Continuous Deployment" refers to automated pipelines that build, test, and optionally deploy code; these are typically triggered by Git events such as pushes to specific branches or PR creation/updates
Explanation
CI/CD tools (like GitHub Actions, GitLab CI, Jenkins) integrate with Git repositories by listening for events (pushes, PRs, tags) and running defined workflows in response, automating testing and deployment.
1
How does Git internally store the content of files and directories — what are "blobs", "trees", and "commits"?
Correct Answer
A "blob" stores a file's raw compressed content, identified by its hash; a "tree" represents a directory, listing blobs and other trees with names and modes; a "commit" points to a root tree representing project state, plus metadata and parent references
Explanation
This object model (blobs, trees, commits, and tags) forms a content-addressable filesystem — identical file content across different commits is stored only once as the same blob, since the SHA-1 hash is based purely on content.
2
What is the difference between Git's "object database" and the "index" (staging area) at a low level?
Correct Answer
The object database (.git/objects) is a content-addressable store of all blobs, trees, commits, and tags ever created, forming permanent history, while the index (.git/index) is a single file representing the next commit's planned tree
Explanation
Understanding this distinction clarifies operations like "git add" (updates the index to match a working directory file's blob) and "git commit" (creates a new tree/commit from the index's current state) — files in the object database are immutable once written.
3
What is "git gc" (garbage collection), and why might "loose objects" accumulate in a repository?
Correct Answer
"git gc" optimizes the repository by compressing loose objects, individual object files created during normal operations like commits, into efficient "packfiles", and removes objects no longer reachable from any reference after a grace period
Explanation
Every new commit, blob, or tree initially creates a "loose object" file; over time these accumulate, and "git gc" (often run automatically) packs them into compact packfiles for storage efficiency and faster access.
4
How does Git determine whether a file has been "renamed" between two commits, given that it doesn't explicitly store rename operations?
Correct Answer
Git compares content of files added in one commit against files deleted in the previous one, and if similarity exceeds a configurable threshold (default ~50%), it heuristically reports the pair as a rename, at diff/log time, not commit time
Explanation
Because rename detection is heuristic and based on content similarity (not stored explicitly), commands like "git log --follow" or "git diff -M" can sometimes miss renames if the file content changed too significantly alongside the rename.
5
What is the difference between "git merge --squash" and a regular "git merge" followed by squashing via interactive rebase?
Correct Answer
"git merge --squash" stages all changes from the merged branch as a single change, but does NOT create a commit or record any merge relationship — you must commit manually, and the branch's individual history and parent link are not preserved at all
Explanation
"--squash" is useful when you want the combined changes of a feature branch as a single commit on the target branch, with absolutely no trace of the source branch's history or that a merge occurred (no merge commit, no parent reference to the feature branch).
6
What is "the three-way merge algorithm" and what role does the "merge base" (common ancestor) play in it?
Correct Answer
A three-way merge compares three versions of a file — the common ancestor ("merge base") and the two divergent branch versions — to determine, per region, whether only one side changed it (auto-resolve) or both sides changed it differently (conflict)
Explanation
Without the merge base as a reference point, Git couldn't distinguish "branch A added this line" from "branch B deleted this line" — comparing against the common ancestor lets Git apply non-overlapping changes automatically and flag only truly conflicting overlaps.
7
What is "git filter-branch" (or the more modern "git filter-repo") used for, and why is it considered dangerous on shared repositories?
Correct Answer
These tools rewrite history across many commits, e.g. removing a sensitive file committed by mistake, but since they change commit hashes for every affected commit and descendant, clones of the old history end up diverged, needing force-push and re-clone
Explanation
Because rewriting history changes the SHA-1 of every affected commit (and all commits built on top of them), this is one of the most disruptive Git operations for collaborators — it should be coordinated carefully, often followed by everyone re-cloning the repository.
8
What is the purpose of Git's "packed-refs" file, and how does it relate to loose refs in ".git/refs/"?
Correct Answer
Branch and tag refs are normally stored as small "loose" files under ".git/refs/", but as a repo accumulates many refs, Git periodically consolidates them into one ".git/packed-refs" file — a ref can be loose (taking precedence), packed, or both
Explanation
This optimization avoids the filesystem overhead of having thousands of tiny individual files for repositories with many branches and tags, while still allowing newly created/updated refs to exist as loose files until the next repacking.
9
What does it mean for Git to use "content-addressable storage", and what guarantee does this provide?
Correct Answer
Every object (blob, tree, commit, tag) is identified by a hash computed from its own content, so the same content always produces the same identifier — if even a single bit changes, its hash and identity change too, giving strong integrity verification
Explanation
This property is why Git can detect corruption (a changed object would no longer match its hash-derived filename/identifier) and why identical content (e.g. the same file in different commits) is automatically deduplicated, since it produces the same hash and is stored once.
10
What is the difference between "git rebase" and "git rebase --onto"?
Correct Answer
A plain "git rebase <base>" replays the branch's commits since diverging from <base> onto its tip, while "git rebase --onto <newbase> <oldbase> <branch>" replays only commits unique to <branch> since <oldbase> onto <newbase>, for moving a branch elsewhere
Explanation
"--onto" gives precise control over the range of commits being replayed and their new base, which is useful in advanced workflows like removing an unwanted intermediate branch from a commit's ancestry or extracting part of a branch's history onto a fresh base.
11
How do Git "hooks" differ between client-side and server-side, and what is a common server-side use case for "pre-receive" hooks?
Correct Answer
Client-side hooks (pre-commit, post-checkout) run locally and aren't transferred on clone, while server-side hooks (pre-receive, update) run remotely on push — "pre-receive" can enforce policies like rejecting force-pushes
Explanation
Because client-side hooks live in the local ".git/hooks" directory and aren't version-controlled or transferred via clone/push, server-side hooks are essential for enforcing policies that cannot be bypassed by individual developers' local configurations.
12
What is "git worktree prune" and when might dangling worktree references occur?
Correct Answer
If a linked worktree's directory is deleted manually (e.g. "rm -rf") instead of via "git worktree remove", the main repository retains stale administrative metadata referring to that now-nonexistent worktree; "git worktree prune" cleans this up
Explanation
This is a good example of how Git maintains administrative state (in ".git/worktrees/") outside of the actual checked-out directories — manual filesystem operations can leave that metadata out of sync, requiring explicit cleanup commands.
13
How does "git log" determine commit order when displaying history, and what is the difference between "--topo-order" and the default chronological ordering when branches have merge commits?
Correct Answer
By default, "git log" generally orders commits by date, which can interleave commits from different branches by timestamp; "--topo-order" ensures no commit shows before its descendants, so a feature branch's commits appear together before its merge commit
Explanation
This distinction matters when timestamps don't reflect the logical order of integration — e.g. if a long-lived branch with old commit dates is merged later, default date-based ordering might interleave its commits confusingly among more recent ones, whereas "--topo-order" keeps the graph structure coherent.
14
What is a "shallow clone" limitation when it comes to operations like "git push" or fetching specific history later?
Correct Answer
A shallow clone ("--depth N") lacks full history beyond that depth, causing issues with operations needing to traverse history, like certain merges, blame, or rebasing onto older commits; getting more history later needs "unshallowing" or a deeper fetch
Explanation
Shallow clones are great for CI/CD where only the latest code matters and history isn't needed, but operations requiring historical context (rebase onto an old commit, full blame, certain merge scenarios) may fail or behave unexpectedly until the necessary history is fetched.
15
In a Git repository with submodules, what does it mean that the parent repository tracks a specific "commit" of the submodule rather than a "branch"?
Correct Answer
The parent repo stores a reference (a "gitlink" entry) pointing to one exact commit hash in the submodule's repo; even as the submodule's branch advances, the parent keeps referencing that pinned commit until someone updates and commits the new reference
Explanation
This pinning behavior provides reproducibility (the parent project always builds against a known-good submodule state) but requires deliberate action ("cd" into the submodule, checkout/pull the desired commit, then commit the updated gitlink in the parent) to "bump" the submodule version.
16
What is "git's ORIG_HEAD" reference, and when is it typically set?
Correct Answer
ORIG_HEAD is automatically set by commands that significantly change HEAD, like "git merge", "git rebase", or "git reset", to record where HEAD pointed immediately before — a quick undo via "git reset --hard ORIG_HEAD" if something goes wrong
Explanation
ORIG_HEAD acts as a one-step "undo" safety net for potentially history-altering operations — for example, after a problematic merge or rebase, "git reset --hard ORIG_HEAD" quickly restores the branch to its pre-operation state.
17
What is the difference between "git merge-base" and simply looking at the parent of the current commit?
Correct Answer
"git merge-base <branch1> <branch2>" finds the best common ancestor shared by both branches' histories, possibly many commits back, not simply either branch's immediate parent — used for three-way merges and "git diff branch1...branch2"
Explanation
Finding the merge base is fundamental to how Git computes diffs between diverged branches (e.g. "git diff main...feature" shows changes on "feature" since it diverged from "main", using the merge base as the starting point, rather than a direct two-way diff of the tips).
18
Why can rewriting a single early commit in a long history (e.g. via interactive rebase to edit a commit from months ago) be considered an expensive and disruptive operation?
Correct Answer
Because a commit's hash depends on its content plus its parent's hash, changing any commit changes its hash, and since descendants reference their parent by hash, all descendants must be rewritten too, cascading through the rest of history
Explanation
This cascading hash-rewrite is why rebasing/amending shared history is so disruptive to collaborators — every commit after the edited one effectively becomes a "new" commit object, even though its content diff relative to its (also new) parent might be identical to before.
19
What is the purpose of Git's "sparse-checkout" feature, and what problem does it solve for very large repositories (monorepos)?
Correct Answer
Sparse-checkout lets a clone populate the working directory with only a subset of the repo's files/directories, while still having the full object database and history available, reducing time and disk space for working in a small part of a huge monorepo
Explanation
This is especially useful for monorepos where a single developer might only need to work within one project's subdirectory — sparse-checkout avoids checking out potentially massive amounts of unrelated code into the working directory while preserving full history access for the included paths.
20
What does it mean that Git branches are "cheap" compared to branching in some older version control systems (like Subversion)?
Correct Answer
In Git, a branch is just a small file containing a commit hash (a pointer), so creating one is nearly instant and takes negligible storage, whereas Subversion branching meant copying the entire directory tree on the server, a slow, storage-heavy operation
Explanation
This low cost of branching is foundational to Git-based workflows that encourage frequent branching for features, experiments, and bugfixes — a practice that would be far more cumbersome in systems where each branch represents a significant copy operation.