AI Hints
Home›Git & GitHub Tutorial›Interview Questions 1
Git & GitHub · Lesson 134 of 144

Interview Questions: Branches

Merge, rebase and conflicts.

⏱ 2 min read▶ Video at 2:25:59🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Branching questions are favourites, because they show whether you've really worked in a team. Here are the classics.

Interview Questions: Branches
From the video: Interview Questions: Branches
  • Interviewers love these
  • They show real teamwork
  • The classics

Merge versus rebase?

Question four. What's the difference between merge and rebase? Merge combines branches by creating a merge commit, and never changes existing commits. Rebase replays your commits on top of another branch, creating new commits, for a straight history. Then add the golden rule. Never rebase commits that others already have.

Merge

  • Merge commit
  • History unchanged
  • Safe for shared work

Rebase

  • Replays commits
  • Straight history
  • Only for local work

How do you resolve a merge conflict?

Question five. How do you resolve a merge conflict? Open the conflicted files. Find the markers, decide on the final content, and remove the markers. Then git add the files, and commit, or continue the rebase. And mention that you'd talk to the teammate who made the other change.

Openthe conflicted files
Decidekeep, combine, rewrite
Removethe markers
Finishgit add, then commit

Fetch versus pull?

Question six. What's the difference between git fetch and git pull? Fetch downloads new commits from the remote, but doesn't change your branch or files. Pull is fetch, followed by a merge, or a rebase, into your current branch.

git fetch

  • Downloads only
  • Updates origin/main
  • Safe to run anytime

git pull

  • Fetch + merge
  • Updates your branch
  • Changes your files

Summary

Merge versus rebase, resolving conflicts, and fetch versus pull. Next, questions about undoing things.

Key takeaways
  • Merge vs rebase
  • Fix conflicts calmly
  • Pull = fetch + merge
Next up: Interview Questions: Undoing — reset, revert and more