Sample questions
Question 1Easy
Which command lists the local branches?
git remotegit branchgit listgit show-branches --all
Answer: B. git branch
Explanation
git branch lists local branches and marks the current one with *. Add -a to include remote-tracking branches.
Step-by-step solution
- git branch with no arguments lists local branches.
- The current branch is marked with *.
- -a also shows remote-tracking branches.
Why the other options are wrong
- A. git remote lists remotes, not branches.
- C. git list is not a Git command.
- D. show-branches is not a Git command (git show-branch exists but shows commits).
Tip: git branch = local; -r = remote; -a = all.
Question 2Easy
Which command creates a branch dev and switches to it (Git 2.23+)?
- git switch dev
- git switch -c dev
- git branch -m dev
- git merge dev
Answer: B. git switch -c dev
Explanation
switch -c creates and switches. git checkout -b dev does the same.
Step-by-step solution
-c means create.- Git adds the branch at HEAD.
- HEAD moves to it.
Why the other options are wrong
- A. Without
-c, the branch must already exist. - C.
-m renames. - D.
merge integrates branches.
Question 3Easy
What does git switch - do?
- Switches back to the previously checked-out branch
- Deletes the current branch and then switches to the default branch
- Switches to the first commit
- Lists all branches
Answer: A. Switches back to the previously checked-out branch
Explanation
The - shortcut means the previous branch, like cd - in a shell.
Step-by-step solution
- Git remembers the last branch.
- refers to it.- HEAD moves back.
Why the other options are wrong
- B. Delete is
branch -d. - C. Not the meaning of
-. - D. Listing is
git branch.
Question 4Easy
Which command creates a new branch named feature and switches to it?
git checkout feature --newgit switch -c featuregit branch feature --gogit merge feature
Answer: B. git switch -c feature
Explanation
git switch -c feature (or the older git checkout -b feature) creates the branch and switches to it in one step.
Step-by-step solution
- git switch changes branches.
- -c creates the branch first.
- So git switch -c feature creates and switches (older form: git checkout -b feature).
Why the other options are wrong
- A. --new is not a checkout option.
- C. --go is not a git branch option.
- D. git merge combines branches.
Tip: Create and switch: switch -c or checkout -b.
Question 5Medium
In a file with a merge conflict, what does the section between <<<<<<< HEAD and ======= contain?
- The version from the branch being merged in
- The version from your current branch
- Git's suggested resolution
- The common ancestor's version
Answer: B. The version from your current branch
Explanation
The part after <<<<<<< HEAD is your current branch's version, and the part between ======= and >>>>>>> branch-name is the incoming version.
Step-by-step solution
- Conflict markers split the two versions.
- Between <<<<<<< HEAD and ======= is your current branch's version.
- Between ======= and >>>>>>> is the incoming branch's version.
Why the other options are wrong
- A. The incoming version is after =======.
- C. Git does not propose a resolution in the markers.
- D. The common ancestor appears only with diff3 style, in a ||||||| section.
Tip: HEAD on top = yours; bottom = theirs.
Question 6Medium
What happens when you git checkout other while holding uncommitted edits to a file that differs between the two branches?
- Changes are silently discarded so that the checkout can always succeed
- Git refuses and asks you to commit or stash first
- Git auto-commits them
- Changes are silently carried and always merged
Answer: B. Git refuses and asks you to commit or stash first
Explanation
To protect uncommitted work, Git aborts the switch if it would overwrite local edits.
Step-by-step solution
- Edits touch a file that differs.
- Git detects the overwrite risk.
- It stops with an error.
Why the other options are wrong
- A. Git never silently discards edits.
- C. Git never commits on its own.
- D. It carries edits only if no conflict arises.
Question 7Medium
What does git merge --no-ff feature do?
- Squashes all commits into one
- Always creates a merge commit, even when a fast-forward is possible
- Refuses to merge if a fast-forward is possible
- Merges without checking for conflicts
Answer: B. Always creates a merge commit, even when a fast-forward is possible
Explanation
--no-ff forces a merge commit, which keeps a visible record that a feature branch existed.
Step-by-step solution
- Normally Git fast-forwards when it can.
- --no-ff forces a merge commit anyway.
- This records that a feature branch existed and was merged.
Why the other options are wrong
- A. Squashing is --squash.
- C. --ff-only refuses non-fast-forward merges; --no-ff does the opposite.
- D. Conflicts are always checked.
Tip: --no-ff = always a merge commit.
Question 8Medium
A merge commit created by merging two diverged branches has how many parents?
- One
- Two
- Three
- Zero
Answer: B. Two
Explanation
A true merge commit records the tip of both lines, so it has two parents. Fast-forward merges create no commit.
Step-by-step solution
- Both branch tips are joined.
- The commit has two parent pointers.
HEAD^2 is the merged-in tip.
Why the other options are wrong
- A. That is a normal commit.
- C. That would be an octopus merge of three branches.
- D. Only a root commit has zero.
Question 9Hard
Given this history, which command lists commits that are on feature but not on main?
A---B---C main
\
D---E feature
- git log feature..main
- git log main...feature
- git log feature --not feature
- git log main..feature
Answer: D. git log main..feature
Explanation
X..Y means reachable from Y but not from X, so main..feature gives E and D.
Step-by-step solution
main..feature excludes everything reachable from main.- That removes A and B.
- Leaves D and E.
Why the other options are wrong
- A. That lists C only.
- B. Three dots would list D, E and C (symmetric difference).
- C.
feature --not feature is empty.
Tip: Two dots = in right, not in left.
Question 10Hard
What does git cherry-pick <hash> do?
- Merges the entire branch that contains that commit into the current one
- Moves the commit to the current branch and deletes it from its original branch
- Checks out that commit in detached HEAD state so you can inspect it
- Applies that commit's changes as a new commit here, with a new hash
Answer: D. Applies that commit's changes as a new commit here, with a new hash
Explanation
cherry-pick copies a commit's changes. The new commit has a different parent, so it gets a different hash, and the original commit is left unchanged.
Step-by-step solution
- cherry-pick takes the changes introduced by one commit.
- It applies them on the current branch as a new commit.
- The new commit has a different parent, so a different hash; the original stays.
Why the other options are wrong
- A. It copies one commit, not a whole branch.
- B. The original commit is not removed.
- C. That is git checkout <hash>.
Tip: Cherry-pick copies; it does not move.
Practise all 22 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 →