Interview questions

Git interview questions

30 questions, 30 with model answers. Every member practises all of them free.

Samples

3 of 30 questions.

How does Git merge and rebase differ internally?

Show the answer
  • Merge: creates a new merge commit that has two parents — the tip of the current branch and the tip of the target branch. The full history of both branches is preserved. The commit graph shows a non-linear history with merge nodes.
  • Rebase: replays commits from the current branch on top of the target branch one by one. Each commit gets a new SHA (new parent pointer). The result is a linear history as if the work was always done on top of the target. Original commits are orphaned (garbage-collected eventually).

Internally: rebase uses cherry-pick logic — for each commit, it computes the diff (patch) and applies it to the new base, creating a new commit object.

How do you resolve merge conflicts?

Show the answer
  1. git merge — Git marks conflicting files with <<<<<<<, =======, >>>>>>> markers.
  2. Open the conflicting files and decide which changes to keep (or combine both).
  3. Remove the conflict markers.
  4. git add <resolved_file> to mark it resolved.
  5. git commit to complete the merge.

Tools: git mergetool (opens vimdiff, IntelliJ, VS Code), git diff --conflict to review, git checkout --ours/--theirs to take one side wholesale.

For complex conflicts, git log --merge shows the commits that introduced the conflict.

Difference between git pull, git fetch, and git clone?

Show the answer
CommandWhat it does
git clone Creates a full local copy of a remote repository (all branches, history, objects). One-time operation.
git fetchDownloads new objects and refs from the remote into FETCH_HEAD and remote-tracking branches (e.g., origin/main) but does NOT update your working branch. Safe to run anytime.
git pullgit fetch + git merge (or git rebase with --rebase flag). Updates your working branch. Can introduce unexpected merge commits.

Best practice: Use git fetch + review + git merge/git rebase for explicit control.

27 more in the member app, with practice sets and your own marks. Join free

More topics

Other interview topics.