Skip to content
gitintermediate

Git Advanced Quiz

Rebase, cherry-pick, reflog, stash, reset modes, and advanced Git workflows.

7 questions

By EZ4Code Team

1. What does `git rebase` do?

Replays your commits on top of another branch
Merges two branches automatically
Deletes a branch
Resets the repository
Explanation: `git rebase <branch>` takes your commits and replays them on top of `<branch>`, creating a linear history. Unlike merge, it rewrites commit hashes. Never rebase commits that have been pushed and shared with others — it causes conflicts for collaborators.

2. What is the difference between `git merge` and `git rebase`?

Merge preserves branch history with a merge commit; rebase rewrites history linearly
They are identical
Rebase is always safer
Merge deletes the branch
Explanation: `git merge` creates a merge commit preserving the branch topology. `git rebase` replays your commits on top of the target, producing linear history but rewriting commit hashes. Merge is safer for shared branches; rebase gives cleaner history for local feature branches.

3. What does `git cherry-pick` do?

git cherry-pick abc123
Applies a specific commit from another branch to the current branch
Deletes a commit
Merges an entire branch
Reverts a commit
Explanation: `git cherry-pick <commit>` takes a single commit from anywhere and applies it to your current branch, creating a new commit. Useful for backporting bug fixes. Unlike merge, it doesn't bring the whole branch — just the one commit.

4. What does `git stash` do?

git stash           # save & clean working dir
git stash list       # list stashes
git stash pop        # apply & drop the latest stash
Temporarily saves uncommitted changes without committing them
Deletes uncommitted changes
Commits changes with a default message
Pushes changes to the remote
Explanation: `git stash` shelves your uncommitted changes (staged and unstaged) so you can switch branches or pull updates with a clean working directory. `git stash pop` restores them. Stashes are stored in a stack — `git stash list` shows all of them.

5. What is the difference between `git reset --soft`, `--mixed`, and `--hard`?

soft keeps changes staged; mixed unstages them; hard deletes them
They are identical
soft deletes changes; hard keeps them
mixed is the most destructive
Explanation: `--soft` moves HEAD but keeps changes staged. `--mixed` (default) moves HEAD and unstages changes (but keeps them in the working directory). `--hard` moves HEAD and DELETES all changes — staged and unstaged. `--hard` is destructive and cannot be undone via reflog only with difficulty.

6. What does `git reflog` show?

A log of where HEAD has been — useful for recovering lost commits
The remote branches
The commit history of the current branch
A list of stashes
Explanation: `git reflog` records every change to HEAD (commits, checkouts, resets, rebases). Even after a destructive `reset --hard`, you can use `git reflog` to find the previous HEAD and `git reset --hard <ref>` to recover. It's a local safety net that's not shared.

7. What does `git revert` do (vs `git reset`)?

git revert abc123
Creates a new commit that undoes a previous commit (safe for shared history)
Deletes a commit from history
Resets the working directory
Rebases the branch
Explanation: `git revert <commit>` creates a NEW commit that reverses the changes of the specified commit. It's safe for shared history because it doesn't rewrite existing commits. `git reset` moves HEAD and can rewrite history — dangerous for pushed commits.

More git Quizzes