Git and Branching Workflows Interview Questions
261 multiple-choice tech interview questions on Git and Branching Workflows: Git objects, the index and commits, branches and remotes, merge versus rebase, conflicts and cherry-picking, undo and recovery, stash and worktrees, LFS and submodules, branching strategies, and commit hygiene. Written for technical phone screens and interview prep, organized by subtopic, with a short explanation for every answer. Learn the 39 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 4.1 Objects, the index and commits
- 4.2 Branches, remotes and HEAD
- 4.3 Merging, rebasing and history shape
- 4.4 Conflicts and cherry-picking
- 4.5 Undoing and recovering
- 4.6 Stash, worktrees and daily commands
- 4.7 Bisect, large files, submodules and secrets
- 4.8 Branching strategies
- 4.9 Commit hygiene, hooks and tags
Key terms
4.1 Objects, the index and commits
- Staging area
- The index where changes are prepared for the next commit
- HEAD
- Pointer to the currently checked-out commit
4.3 Merging, rebasing and history shape
- Rebase
- Replays commits onto a new base, rewriting them
- Fast-forward
- Moving a branch pointer ahead without a merge commit
- Squash merge
- Combining a branch's commits into one on merge
4.5 Undoing and recovering
- git revert
- Creates a new commit reversing an earlier one
- Reflog
- Local log of where HEAD and branches have pointed
- git bisect
- Binary search through history for a bad commit
4.8 Branching strategies
- Trunk-based development
- Frequent integration into one main branch
- Branch protection
- Enforced rules for a branch, such as reviews and checks
4.9 Commit hygiene, hooks and tags
- Blob
- File content stored by hash
- Tree object
- A directory of names pointing to blobs and trees
- Detached HEAD
- HEAD points at a commit, not a branch
- Remote-tracking branch
- Local snapshot of a remote branch, like origin/main
- git switch
- Command to switch or create branches
- git restore
- Command to restore files in the worktree or index
- merge-base
- The common ancestor used in a three-way merge
- Three-way merge
- Combining two sides using their common ancestor
- rerere
- Reuse recorded resolution of a conflict
- ORIG_HEAD
- Ref set to HEAD before a reset or merge
- Worktree
- An extra linked checkout of the same repository
- git clean
- Removes untracked files
- Submodule
- A Git repo nested inside another repo, pinned by commit
- Git LFS
- Stores large file contents outside normal Git objects
- git filter-repo
- Tool to rewrite history, replacing filter-branch
- Annotated tag
- A tag object with a message and tagger
- Signed commit
- A commit with a GPG or SSH signature
- pre-commit hook
- A local hook that runs before a commit is created
- Co-authored-by
- A commit trailer naming an additional author
- Bare repository
- A repo without a working tree, used as a remote
- Shallow clone
- A clone with truncated history
- fixup
- An autosquash commit meant to be folded into another
- Sparse checkout
- Checking out only some paths
- Orphan branch
- A branch with no parent commit
- Signed-off-by
- A trailer used for the Developer Certificate of Origin
- Trailer
- A Token: value line at the end of a commit message
- Git hook
- A script Git runs on an event such as commit or push
- Pointer file
- The small LFS text file Git stores instead of a large blob
- git bundle
- A file that carries Git refs and objects for offline transfer
Sample practice questions
What are the three main areas a file moves through in local Git work?
- The cloud, the build server and the developer's laptop
- The working directory, the staging area and the repository
- The trunk, the feature branch and the release tag
- The editor, the compiler and the debugger, in that order
Answer: B. The working directory, the staging area and the repository `git add` moves changes to the staging area; `git commit` records them.
What is a branch in Git?
- A full copy of the repository on disk
- A lightweight movable pointer to a commit
- A separate remote server
- A folder of source files
Answer: B. A lightweight movable pointer to a commit That is why creating branches in Git is cheap.
What is the difference between merge and rebase?
- Rebase preserves the original history exactly, while merge rewrites the existing commits
- They produce exactly the same history, so the choice is purely a matter of taste
- Merge only works on remote branches, while rebase only works on local branches
- Merge joins histories with a merge commit; rebase replays commits onto a new base, linearly
Answer: D. Merge joins histories with a merge commit; rebase replays commits onto a new base, linearly Both integrate changes; they differ in the shape of history they create.
How does Git mark a merge conflict in a file?
- By deleting the conflicting file from the working tree
- By renaming the file with a `.conflict` extension
- With `<<<<<<<`, `=======` and `>>>>>>>` markers
- By refusing to show the file until it's resolved
Answer: C. With `<<<<<<<`, `=======` and `>>>>>>>` markers Edit the file to the desired result, remove the markers, then `git add` and continue.
What is the safe way to undo a commit that has already been pushed to a shared branch?
- `git reset --hard`, followed by a force-push
- Deleting the repository and creating it again
- `git revert <commit>`, adding a reversing commit
- Editing the commit on the server by hand
Answer: C. `git revert <commit>`, adding a reversing commit Revert keeps history intact for everyone else.
What does `git stash` do?
- Deletes all of your uncommitted changes permanently, with no undo
- Temporarily shelves uncommitted changes so you can switch tasks
- Pushes your uncommitted changes up to the remote repository
- Creates a new branch from the current commit and switches to it
Answer: B. Temporarily shelves uncommitted changes so you can switch tasks `git stash pop` reapplies the most recent stash.
A secret key was committed and pushed. What is the most important first step?
- Delete the file in a new commit and then simply move on from there
- Make the repository private, and then don't do anything else about it
- Revoke and rotate it now, then purge it from history and add scanning
- Rename the variable that held the secret so it's harder to search for
Answer: C. Revoke and rotate it now, then purge it from history and add scanning Once pushed, assume the secret is compromised; history rewriting alone is not enough.
What is trunk-based development?
- Every feature lives on its own long-running branch for months before it's merged
- Integrating small changes into main at least daily, with feature flags for unfinished work
- Developers never merge their work into main; releases are cut from branches
- Each developer keeps their own personal main branch that's never shared
Answer: B. Integrating small changes into main at least daily, with feature flags for unfinished work It is associated with high-performing teams in DORA research.
What is a branch protection rule?
- A setting enforcing required reviews, passing checks and no force-pushes
- A rule that hides a branch from every user except its creator
- A setting that encrypts every file stored on the branch
- A scheduled job that backs up the branch to another server
Answer: A. A setting enforcing required reviews, passing checks and no force-pushes GitHub rulesets and Azure Repos branch policies provide this.
What is a Git commit?
- A list of line-by-line diffs only, with no record of the full files
- A backup copy of the repository stored on a remote server
- Another name for a branch that points at the latest change
- A hashed snapshot of tracked files with author, message and parents
Answer: D. A hashed snapshot of tracked files with author, message and parents Git stores snapshots, using hashing to deduplicate unchanged content.