Git Beginner Quiz
30 questions on Git Basics.
Question 1: What is Git primarily used for?
- A. Writing code in Python
- B. Version control and source code management β (correct answer)
- C. Hosting websites
- D. Designing user interfaces
Explanation: Git tracks changes in source code during software development, allowing multiple developers to collaborate and revert to older versions if necessary.
Question 2: Which command initializes a new Git repository?
- A. git start
- B. git create
- C. git init β (correct answer)
- D. git new
Explanation: The git init command creates a new, empty Git repository (or reinitializes an existing one) in the current directory.
Question 3: What is the "Staging Area" in Git?
- A. A server where the code is hosted
- B. A testing environment for the app
- C. A temporary space where changes are gathered and prepared before they are committed β (correct answer)
- D. The final branch of a project
Explanation: The staging area acts as a draft space where you carefully select exactly which modified files will be included in the next commit.
Question 4: Which command adds all modified files to the staging area?
- A. git add . β (correct answer)
- B. git stage all
- C. git commit -a
- D. git push
Explanation: The git add . command stages all changes in the current directory and its subdirectories.
Question 5: Which command saves the staged changes to the local repository's history?
- A. git save
- B. git commit -m "Message" β (correct answer)
- C. git push
- D. git update
Explanation: git commit takes a snapshot of the staging area and permanently saves it to the local repository timeline.
Question 6: What does git status do?
- A. Shows the current internet connection status
- B. Lists all branches in the repository
- C. Shows which files are modified, staged, and untracked β (correct answer)
- D. Uploads the code to GitHub
Explanation: git status is the most frequently used command to see the current state of your working directory and staging area.
Question 7: Which command downloads an entire remote repository to your local machine?
- A. git download
- B. git pull
- C. git fetch
- D. git clone β (correct answer)
Explanation: git clone <url> copies an existing Git repository from a remote server to your local machine.
Question 8: What is the difference between git fetch and git pull?
- A. They are exactly the same
- B.
fetch only downloads new data, while pull downloads data and immediately merges it into your current branch β (correct answer)
- C.
pull only works on the master branch
- D.
fetch uploads data to the server
Explanation: git pull is essentially git fetch followed immediately by git merge.
Question 9: Which command uploads your local commits to a remote repository?
- A. git upload
- B. git send
- C. git push β (correct answer)
- D. git commit --remote
Explanation: git push transfers your local repository's commits to the remote repository (like GitHub or GitLab).
Question 10: How do you view the history of commits in a repository?
- A. git history
- B. git log β (correct answer)
- C. git show
- D. git timeline
Explanation: git log lists the commits made in the repository in reverse chronological order.
Question 11: What is a "Branch" in Git?
- A. A backup of the code
- B. An independent line of development β (correct answer)
- C. A folder structure
- D. An error log
Explanation: Branching allows you to diverge from the main line of development and continue doing work without messing with the main codebase.
Question 12: Which command lists all local branches?
- A. git branches
- B. git show-branch
- C. git branch β (correct answer)
- D. git list
Explanation: Running git branch without any arguments displays all local branches, highlighting the current active branch with an asterisk.
Question 13: Which command creates a new branch and immediately switches to it?
- A. git checkout -b branch_name
- B. git branch -new branch_name
- C. git switch -c branch_name
- D. Both A and C β (correct answer)
Explanation: git checkout -b is the traditional command, while git switch -c is a newer, explicitly named command that does exactly the same thing.
Question 14: What is the default name of the primary branch in modern Git repositories?
- A. primary
- B. trunk
- C. main (or master) β (correct answer)
- D. head
Explanation: Historically, the default branch was master. Modern platforms like GitHub now default to main.
Question 15: What does the HEAD pointer represent in Git?
- A. The topmost commit of the main branch
- B. A reference to the currently checked-out commit/branch β (correct answer)
- C. The repository owner
- D. The very first commit ever made
Explanation: HEAD is a pointer that tells Git exactly what snapshot of the project you are currently viewing and working on.
Question 16: How do you rename the current branch?
- A. git branch -r new_name
- B. git branch -m new_name β (correct answer)
- C. git rename branch new_name
- D. git checkout -rename new_name
Explanation: The -m flag stands for "move/rename". It safely renames the current active branch.
Question 17: What does the .gitignore file do?
- A. It deletes ignored files from your computer
- B. It tells Git which files or directories to intentionally leave untracked and avoid committing β (correct answer)
- C. It logs errors that Git ignores
- D. It prevents other users from downloading your repository
Explanation: Files like compiled binaries, node_modules, and .env files containing passwords should always be listed in .gitignore.
Question 18: Which command shows the exact line-by-line differences between the working directory and the staging area?
- A. git compare
- B. git show
- C. git status --lines
- D. git diff β (correct answer)
Explanation: git diff highlights exactly what has been modified (additions in green, deletions in red) before you stage them.
Question 19: How do you amend (modify) the most recent commit without creating a new one?
- A. git commit --edit
- B. git commit --amend β (correct answer)
- C. git commit --update
- D. git modify
Explanation: git commit --amend allows you to change the previous commit's message or add forgotten files to it.
Question 20: What does git remote -v do?
- A. Removes all remote branches
- B. Shows the URLs of the remote repositories currently configured β (correct answer)
- C. Upgrades Git to the latest version
- D. Connects to a virtual server
Explanation: The -v (verbose) flag displays the fetch and push URLs for remotes like origin.
Question 21: Which command integrates changes from one branch into your current branch?
- A. git pull
- B. git combine
- C. git merge β (correct answer)
- D. git insert
Explanation: git merge feature-branch will take the commits from the feature branch and apply them to your currently checked-out branch.
Question 22: If you mistakenly stage a file with git add, how do you unstage it without losing the file's modifications?
- A. git unadd file_name
- B. git restore --staged file_name β (correct answer)
- C. git rm file_name
- D. git checkout file_name
Explanation: git restore --staged safely moves the file out of the staging area back to the modified (untracked) state. (Older Git versions used git reset HEAD).
Question 23: What happens during a "Fast-Forward" merge?
- A. Git creates a new merge commit
- B. Git skips the staging area
- C. Git simply moves the branch pointer forward because there is no divergent history β (correct answer)
- D. Git deletes the merged branch automatically
Explanation: If the main branch hasn't changed since you created your feature branch, Git just points main to your latest commit, moving it "fast-forward".
Question 24: Which command deletes a local branch named testing?
- A. git branch -d testing β (correct answer)
- B. git rm testing
- C. git branch --delete-force testing
- D. git delete branch testing
Explanation: git branch -d safely deletes a branch, provided its changes have already been merged. Use -D to force delete an unmerged branch.
Question 25: What is "origin" in Git terminology?
- A. The very first commit
- B. The default name Git gives to the server you cloned from β (correct answer)
- C. The local master branch
- D. The author of the repository
Explanation: When you run git clone, Git automatically sets up a remote connection called "origin" pointing back to the source URL.
Question 26: What is a "Detached HEAD" state?
- A. When the repository loses connection to the server
- B. When you checkout a specific commit hash directly rather than a branch name β (correct answer)
- C. When a branch has no commits
- D. When the
.git folder gets corrupted
Explanation: In this state, HEAD points to a specific snapshot in time, not a branch. Any new commits made here will be lost when you switch branches unless you create a new branch.
Question 27: How can you view a condensed, one-line-per-commit history?
- A. git log --short
- B. git log --oneline β (correct answer)
- C. git log --condensed
- D. git history --mini
Explanation: git log --oneline formats the history clearly, showing only the short hash and the commit message.
Question 28: What command is used to permanently discard all local modifications in tracked files, reverting them back to the last commit?
- A. git restore .
- B. git clean -all
- C. git reset --hard β (correct answer)
- D. git drop changes
Explanation: git reset --hard is a dangerous command that permanently deletes any uncommitted changes in your tracked files.
Question 29: Which command uploads a new local branch to the remote repository for the very first time?
- A. git push
- B. git push -u origin branch_name β (correct answer)
- C. git send origin branch_name
- D. git branch --push
Explanation: The -u (upstream) flag links your local branch to the remote branch, allowing you to use simply git push or git pull in the future.
Question 30: How do you remove a file from Git tracking without deleting it from your local hard drive?
- A. git rm --cached file_name β (correct answer)
- B. git untrack file_name
- C. git rm file_name
- D. git delete --soft file_name
Explanation: git rm --cached removes the file from the staging area and Git's memory, but leaves the physical file untouched on your disk (useful after updating .gitignore).