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

  1. 4.1 Objects, the index and commits
  2. 4.2 Branches, remotes and HEAD
  3. 4.3 Merging, rebasing and history shape
  4. 4.4 Conflicts and cherry-picking
  5. 4.5 Undoing and recovering
  6. 4.6 Stash, worktrees and daily commands
  7. 4.7 Bisect, large files, submodules and secrets
  8. 4.8 Branching strategies
  9. 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

  1. What are the three main areas a file moves through in local Git work?

    1. The cloud, the build server and the developer's laptop
    2. The working directory, the staging area and the repository
    3. The trunk, the feature branch and the release tag
    4. 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.

  2. What is a branch in Git?

    1. A full copy of the repository on disk
    2. A lightweight movable pointer to a commit
    3. A separate remote server
    4. A folder of source files

    Answer: B. A lightweight movable pointer to a commit That is why creating branches in Git is cheap.

  3. What is the difference between merge and rebase?

    1. Rebase preserves the original history exactly, while merge rewrites the existing commits
    2. They produce exactly the same history, so the choice is purely a matter of taste
    3. Merge only works on remote branches, while rebase only works on local branches
    4. 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.

  4. How does Git mark a merge conflict in a file?

    1. By deleting the conflicting file from the working tree
    2. By renaming the file with a `.conflict` extension
    3. With `<<<<<<<`, `=======` and `>>>>>>>` markers
    4. 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.

  5. What is the safe way to undo a commit that has already been pushed to a shared branch?

    1. `git reset --hard`, followed by a force-push
    2. Deleting the repository and creating it again
    3. `git revert <commit>`, adding a reversing commit
    4. Editing the commit on the server by hand

    Answer: C. `git revert <commit>`, adding a reversing commit Revert keeps history intact for everyone else.

  6. What does `git stash` do?

    1. Deletes all of your uncommitted changes permanently, with no undo
    2. Temporarily shelves uncommitted changes so you can switch tasks
    3. Pushes your uncommitted changes up to the remote repository
    4. 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.

  7. A secret key was committed and pushed. What is the most important first step?

    1. Delete the file in a new commit and then simply move on from there
    2. Make the repository private, and then don't do anything else about it
    3. Revoke and rotate it now, then purge it from history and add scanning
    4. 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.

  8. What is trunk-based development?

    1. Every feature lives on its own long-running branch for months before it's merged
    2. Integrating small changes into main at least daily, with feature flags for unfinished work
    3. Developers never merge their work into main; releases are cut from branches
    4. 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.

  9. What is a branch protection rule?

    1. A setting enforcing required reviews, passing checks and no force-pushes
    2. A rule that hides a branch from every user except its creator
    3. A setting that encrypts every file stored on the branch
    4. 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.

  10. What is a Git commit?

    1. A list of line-by-line diffs only, with no record of the full files
    2. A backup copy of the repository stored on a remote server
    3. Another name for a branch that points at the latest change
    4. 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.

Practice all 261 questions

More Development Practices