Sample questions
Question 1Easy
Which command replays your current branch commits on top of main?
- git merge --rebase main
- git reset main
- git replay main
- git rebase main
Answer: D. git rebase main
Explanation
git rebase main takes your commits since divergence and reapplies them on the tip of main, producing a linear history.
Step-by-step solution
- Find commits not in main.
- Reapply them one by one on main.
- The commits get new hashes.
Why the other options are wrong
- A. No such option for merge.
- B.
reset moves the branch pointer. - C.
replay is not the usual rebase command.
Question 2Easy
A rebase is giving conflicts you do not want to solve. Which command returns the branch to how it was before?
- git rebase --abort
- git rebase --skip
- git reset --hard origin
- git rebase --undo
Answer: A. git rebase --abort
Explanation
--abort cancels the rebase and restores the original branch state.
Step-by-step solution
- Rebase is in progress.
--abort stops it.- The branch returns to its original tip.
Why the other options are wrong
- B.
--skip drops the current commit. - C. That may lose other work.
- D.
--undo does not exist.
Question 3Medium
What is the commonly cited "golden rule" of rebasing?
- Never rebase a branch that exists only on your local machine
- Do not rebase commits that others may already have pulled
- Always rebase onto main before every single commit you make
- Only ever rebase the main branch, never feature branches
Answer: B. Do not rebase commits that others may already have pulled
Explanation
Rebasing rewrites commits. If others already have the old commits, their history diverges from yours and becomes hard to reconcile.
Step-by-step solution
- Rebasing creates new commits and drops the old ones from your branch.
- If others already pulled the old commits, histories diverge.
- So do not rebase commits others may have.
Why the other options are wrong
- A. Local-only branches are exactly where rebasing is safe.
- C. No rule requires rebasing before every commit.
- D. Rebasing shared main is the most dangerous case.
Tip: Rebase private work, merge public work.
Question 4Medium
Compared with merging, what is the main effect of rebasing a feature branch before integrating it?
- It preserves the exact original hashes of every commit
- It produces a linear history without a merge commit
- It deletes the old commits from the remote immediately
- It guarantees that no merge conflicts can ever happen
Answer: B. It produces a linear history without a merge commit
Explanation
Rebase makes it look as if the work started from the latest main, giving a straight line of commits. Merge keeps the real branching structure.
Step-by-step solution
- Rebasing replays feature commits on top of main.
- Integrating then needs no merge commit.
- History becomes a single straight line.
Why the other options are wrong
- A. Rebased commits get new hashes.
- C. Rebase does not touch the remote by itself.
- D. Conflicts can still happen during rebase.
Tip: Want a straight-line history? Rebase before merging.
Question 5Medium
During a messy rebase you want to give up and return the branch to exactly how it was before the rebase. What do you run?
git rebase --continuegit rebase --abortgit rebase --quitgit reset --soft HEAD
Answer: B. git rebase --abort
Explanation
--abort stops the rebase and resets HEAD to the original branch. --quit stops the rebase but leaves HEAD where it currently is.
Step-by-step solution
- You want everything back as before the rebase.
- git rebase --abort stops it and restores the original branch.
- --quit stops but leaves HEAD where it currently is.
Why the other options are wrong
- A. --continue carries on with the rebase.
- C. --quit does not restore the original state.
- D. reset --soft HEAD does nothing useful here.
Tip: Panic during rebase? --abort.
Question 6Medium
What does git rebase main do when run on a feature branch?
- Deletes feature and recreates it as a copy of the main branch
- Merges main into feature, creating a merge commit on feature
- Pushes the feature commits to main on the remote repository
- Replays the feature commits on top of main as new commits
Answer: D. Replays the feature commits on top of main as new commits
Explanation
Rebase reapplies your commits one by one onto the new base. The resulting commits have new hashes, and history becomes linear.
Step-by-step solution
- Find the commits on feature that are not on main.
- Move feature's base to main's tip.
- Replay those commits one by one as new commits with new hashes.
Why the other options are wrong
- A. Rebase keeps your feature commits.
- B. Merging creates a merge commit; rebase does not.
- C. Rebase is local; it pushes nothing.
Tip: Rebase = replay my commits on a new base.
Question 7Medium
After a rebase, why do your commits have different hashes?
- Git compresses the objects again so the stored identifier gets updated
- The author name is changed
- Their parent changed, so each commit is rewritten as a new object
- Hashes are random per push
Answer: C. Their parent changed, so each commit is rewritten as a new object
Explanation
A commit hash depends on its tree, parent and metadata. A new parent produces a new hash even if the diff is identical.
Step-by-step solution
- Hash covers parent id.
- Rebase gives new parents.
- So new hashes result.
Why the other options are wrong
- A. Compression does not change ids.
- B. The author is preserved.
- D. Hashes are deterministic.
Question 8Medium
What does the edit command do in an interactive rebase todo list?
- Opens the commit message editor only, without stopping the rebase
- Stops at that commit so you can amend it or split it
- Deletes the commit
- Skips the commit
Answer: B. Stops at that commit so you can amend it or split it
Explanation
With edit, rebase pauses after applying the commit so you can change it, then continue with git rebase --continue.
Step-by-step solution
- Rebase pauses at the commit.
- Amend or split the commit.
git rebase --continue resumes.
Why the other options are wrong
- A. That is
reword. - C. That is
drop. - D. Skipping is not what
edit does.
Question 9Hard
In which order does git rebase -i HEAD~3 list the commits in the todo file?
- Newest first, exactly like the output of git log
- Alphabetical by message
- Random
- Oldest first, newest last
Answer: D. Oldest first, newest last
Explanation
Commits are applied in order, so the oldest is at the top. This is the opposite of git log.
Step-by-step solution
git log shows newest first.- The todo list shows oldest first.
- The top line is applied first.
Why the other options are wrong
- A. That is the log order.
- B. Order is chronological.
- C. Order is deterministic.
Tip: Todo list reads like a story: top to bottom.
Question 10Hard
What does git rebase --onto main featA featB do (featB branched from featA)?
- Merges featA and featB together and then merges the result into main
- Rebases featA onto featB
- Replays commits of featB that are not in featA onto main
- Deletes featA
Answer: C. Replays commits of featB that are not in featA onto main
Explanation
--onto <new-base> <upstream> <branch> takes commits in upstream..branch and replays them on <new-base>.
Step-by-step solution
- Select
featA..featB commits. - Replay them on main.
- featB now starts at main.
Why the other options are wrong
- A. Nothing is merged.
- B. Direction is opposite.
- D. No branch is deleted.
Practise all 18 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →