Advanced Git Beginner Quiz
30 questions on Advanced Git Commands.
Question 1: What does the git stash command do?
- A. Deletes all uncommitted changes
- B. Temporarily shelves (or stashes) changes you've made to your working directory so you can work on something else, and then come back and re-apply them later β (correct answer)
- C. Commits the changes secretly
- D. Uploads the code to a hidden branch
Explanation: git stash is perfect when you are halfway through a feature but suddenly need to switch branches to fix a critical bug.
Question 2: How do you apply your stashed changes back to your working directory and remove them from the stash list?
- A.
git stash pop β (correct answer)
- B.
git stash apply
- C.
git stash restore
- D.
git stash load
Explanation: git stash pop applies the most recent stash and deletes it. git stash apply applies it but keeps a copy in the stash memory.
Question 3: What does git rebase do?
- A. It merges two branches together by creating a new merge commit
- B. It takes all the commits of your current branch and reapplies them sequentially on top of another branch (like
main), creating a straight, linear history β (correct answer)
- C. It deletes the base branch
- D. It resets the repository to its initial state
Explanation: Rebasing is an alternative to merging that keeps project history clean and easy to read without cluttering it with merge commits.
Question 4: Why is it dangerous to run git rebase on a public branch that other people are using?
- A. It costs server money
- B. It rewrites commit history, meaning other developers' local branches will become out of sync and cause massive conflicts β (correct answer)
- C. It deletes their hard drives
- D. It disables GitHub
Explanation: The golden rule of rebasing: "Never rebase commits that have already been pushed to a public repository."
Question 5: What does the git revert command do?
- A. It permanently deletes a commit and all its history
- B. It creates a brand new commit that contains the exact opposite changes of the specified commit, effectively undoing it safely β (correct answer)
- C. It moves the branch backwards
- D. It deletes the repository
Explanation: Because you cannot rewrite public history, git revert is the safe, standard way to undo a bug that has already been pushed to main.
Question 6: What is the difference between git reset and git revert?
- A. They are exactly the same
- B.
reset moves the branch pointer backward (erasing history), while revert creates a new forward-moving commit that undoes the changes β (correct answer)
- C.
reset is for branches, revert is for files
- D.
reset uploads to GitHub, revert downloads
Explanation: Use reset for private, local mistakes. Use revert for public mistakes already on GitHub.
Question 7: What does git reset --soft HEAD~1 do?
- A. Deletes the last commit and permanently deletes all the files you changed
- B. Undoes the last commit, but keeps all your changed files staged and ready to be re-committed β (correct answer)
- C. Modifies the commit message only
- D. Reboots the server softly
Explanation: A soft reset is perfect when you accidentally committed too early and want to add one more file to the commit.
Question 8: What does git reset --hard HEAD~1 do?
- A. It undoes the last commit and permanently deletes the changes from your hard drive β (correct answer)
- B. It commits the files forcefully
- C. It pushes to GitHub forcefully
- D. It compresses the database
Explanation: --hard is highly destructive. It rewinds history and wipes the working directory clean to match that older point in time.
Question 9: What does the git cherry-pick [commit-hash] command do?
- A. It deletes a specific commit
- B. It grabs a specific commit from another branch and applies a copy of it to your current branch β (correct answer)
- C. It highlights a commit in pink
- D. It squashes all commits
Explanation: Cherry-picking is useful if a teammate wrote a utility function in their branch, and you need that exact function in your branch without merging their entire unfinished feature.
Question 10: What does git reflog (Reference Log) do?
- A. It lists all branches
- B. It keeps a chronological log of every single time the
HEAD pointer moved locally (even for deleted commits or hard resets) β (correct answer)
- C. It logs server errors
- D. It shows the
.gitignore history
Explanation: git reflog is your safety net. If you accidentally run git reset --hard and delete your work, you can use reflog to find the lost commit hash and recover it.
Question 11: What does git clean -fd do?
- A. It formats your hard drive
- B. It permanently deletes all untracked files and directories from your working directory β (correct answer)
- C. It clears the terminal screen
- D. It formats your code to match styling rules
Explanation: If your project is cluttered with build artifacts or temporary files that aren't tracked by Git, git clean wipes them out.
Question 12: How do you create a Git "Tag"?
- A.
git tag v1.0.0 β (correct answer)
- B.
git mark v1.0.0
- C.
git label v1.0.0
- D.
git release v1.0.0
Explanation: Tags act as permanent bookmarks for specific commits, commonly used to mark release versions (like v1.0, v2.0).
Question 13: What does the git blame [filename] command do?
- A. It sends an angry email to the author
- B. It displays the file line-by-line, showing exactly who wrote each line and in which commit β (correct answer)
- C. It deletes the file
- D. It reports the file to GitHub
Explanation: git blame is an incredibly useful debugging tool to find out when a specific line of code was introduced and why.
Question 14: What is an "Interactive Rebase" (git rebase -i)?
- A. A rebase that plays a video tutorial
- B. A tool that opens a text editor, allowing you to manually squash, edit, reorder, or delete specific commits before applying them β (correct answer)
- C. A rebase that asks for your password
- D. A GUI version of Git
Explanation: Interactive rebasing (git rebase -i HEAD~3) is the ultimate tool for cleaning up a messy commit history before opening a Pull Request.
Question 15: In an interactive rebase, what does the squash (or s) command do?
- A. It deletes the commit entirely
- B. It merges the commit into the previous commit, combining their changes and allowing you to rewrite the message β (correct answer)
- C. It zips the file
- D. It executes the commit
Explanation: Squashing is how you turn 5 "WIP" (Work In Progress) commits into 1 clean, professional commit.
Question 16: What does git fetch --all do?
- A. Downloads all files to your desktop
- B. Downloads the latest metadata and commit histories from all configured remote repositories, without merging anything β (correct answer)
- C. Merges all branches automatically
- D. Deletes all local branches
Explanation: This is a safe way to see what your teammates have pushed to GitHub without affecting your current local working directory.
Question 17: What is a Git Hook?
- A. A phishing scam
- B. A script that Git executes automatically before or after events such as commit, push, or receive β (correct answer)
- C. A connection to the internet
- D. A way to pirate software
Explanation: For example, a pre-commit hook can run a code linter. If the linter fails, the hook prevents the commit from being created.
Question 18: Where are Git hooks stored in your repository?
- A. In the
package.json file
- B. In the hidden
.git/hooks directory β (correct answer)
- C. On the desktop
- D. In the
.gitignore file
Explanation: Every Git repository has this folder, containing sample scripts for pre-commit, post-receive, and other hooks.
Question 19: What does git push --force (or -f) do?
- A. It makes the push happen faster
- B. It overwrites the remote repository's history with your local history, permanently destroying any remote commits that you don't have locally β (correct answer)
- C. It forces the server to reboot
- D. It bypasses password authentication
Explanation: Force pushing is extremely dangerous on shared branches. It is mostly used after rebasing a private feature branch.
Question 20: What is a safer alternative to git push --force that won't overwrite a teammate's new commits?
- A.
git push --safe
- B.
git push --force-with-lease β (correct answer)
- C.
git push --gentle
- D.
git push --no-overwrite
Explanation: --force-with-lease checks if anyone else has pushed to the branch since you last fetched. If they have, it aborts the force push.
Question 21: What does git show [commit-hash] do?
- A. It opens the commit on GitHub
- B. It displays the commit's metadata (author, date, message) and the exact code diff (additions/deletions) introduced by that commit β (correct answer)
- C. It reverts the commit
- D. It changes the commit author
Explanation: git show is the quickest way to inspect exactly what changed in a specific commit.
Question 22: What is a "Submodule" in Git?
- A. A smaller hard drive
- B. A Git repository nested completely inside another Git repository β (correct answer)
- C. A deleted folder
- D. A plugin for VS Code
Explanation: Submodules (git submodule add <url>) allow you to keep another project in a subdirectory of your main project, while tracking its specific commits independently.
Question 23: How do you view a list of all your currently stashed items?
- A.
git stash show
- B.
git stash list β (correct answer)
- C.
git stash inventory
- D.
git stash all
Explanation: git stash list will show you stash@{0}, stash@{1}, etc., allowing you to pick which stash to apply.
Question 24: How do you apply a specific stash, like the second one in the list?
- A.
git stash apply stash@{1} β (correct answer)
- B.
git stash apply 2
- C.
git stash load 1
- D.
git stash pop second
Explanation: The stashes are 0-indexed, so stash@{1} is the second most recent stash.
Question 25: What does git bisect do?
- A. It cuts the repository in half to save space
- B. It uses binary search to quickly find exactly which commit introduced a bug β (correct answer)
- C. It merges two branches perfectly
- D. It deletes half your commits
Explanation: You tell git bisect a "good" commit and a "bad" commit. It checks out commits in the middle automatically, asking you to test if the bug is present, drastically reducing debugging time.
Question 26: What does git fetch origin main:main do?
- A. It pushes local changes
- B. It fetches the remote
main branch and automatically updates your local main branch to match it, without needing to check it out first β (correct answer)
- C. It creates a merge conflict
- D. It deletes both branches
Explanation: This is a highly efficient shortcut to keep your local main updated while you remain checked out on a feature branch.
Question 27: What does git commit --amend --no-edit do?
- A. It deletes the commit message
- B. It adds your currently staged files to the previous commit without prompting you to change the commit message β (correct answer)
- C. It cancels the commit
- D. It locks the file
Explanation: This is the fastest way to fix a typo you realized you made right after committing. Stage the fix, run this command, and it's silently added.
Question 28: What is a "shallow clone"?
- A. Cloning only the
.gitignore file
- B. Cloning a repository with truncated history (e.g.,
git clone --depth 1 <url>) to save massive amounts of download time β (correct answer)
- C. Cloning a repository without the code
- D. A clone that deletes itself after an hour
Explanation: If a project has 10 years of history and you only want the latest code to build it, --depth 1 downloads only the most recent commit.
Question 29: If you are on a branch and want to pull the latest changes from main but prefer rebasing over merging, what is the fastest command?
- A.
git pull --rebase origin main β (correct answer)
- B.
git fetch && git rebase
- C.
git merge --rebase
- D.
git update
Explanation: This command fetches the latest main from the server and instantly rebases your current local commits on top of it.
Question 30: What is a "Bare" repository (git init --bare)?
- A. A repository with no files
- B. A repository that doesn't contain a working directory (no physical project files to edit), used exclusively as a central server repository to push to and pull from β (correct answer)
- C. A repository that is public
- D. A repository without security
Explanation: This is exactly how GitHub servers are structured behind the scenes. You cannot edit code directly in a bare repository.