Git MCQ

Git is a distributed version control system that allows teams to work on the same projects without stepping on each other’s toes. It’s one of the most popular tools for developers worldwide. 

In this blog post, we will dive deep into the essential concepts of Git through a set of 25 multiple-choice questions. Each question will have an answer and an explanation to further your understanding.

1. What is Git?

a) Text Editor
b) Compiler
c) Version Control System
d) Operating System

Answer:

c) Version Control System

Explanation:

Git is a distributed version control system that allows multiple users to track and manage changes in software projects.

2. Which command initializes a new Git repository?

a) git new
b) git create
c) git start
d) git init

Answer:

d) git init

Explanation:

The git init command is used to initialize a new Git repository and begin tracking an existing directory.

3. How can you view the commit history in Git?

a) git logs
b) git history
c) git commits
d) git log

Answer:

d) git log

Explanation:

The git log command displays the commit history, showing various details about each commit.

4. Which command adds changes to the staging area in Git?

a) git add
b) git save
c) git upload
d) git stage

Answer:

a) git add

Explanation:

The git add command stages the changes for commit, which means it tracks the new and modified files to be committed.

5. Which command shows the status of changes in the repository?

a) git status
b) git show
c) git view
d) git display

Answer:

a) git status

Explanation:

The git status command displays the list of changed files that are staged, unstaged, and untracked.

6. How do you commit the staged changes?

a) git save
b) git update
c) git commit
d) git store

Answer:

c) git commit

Explanation:

The git commit command captures a snapshot of the changes made and saves it to the version history with a unique ID.

7. What does the .git directory store?

a) Configuration files
b) Source code
c) Project documentation
d) Repository metadata and version history

Answer:

d) Repository metadata and version history

Explanation:

The .git directory contains all the metadata and the object database for the repository. It’s the heart of Git, and the repository itself.

8. Which command creates a new branch in Git?

a) git new branch
b) git branch-new
c) git branch
d) git create-branch

Answer:

c) git branch

Explanation:

Using git branch <branch-name>, you can create a new branch. This doesn’t switch to the new branch; you’d use git checkout or git switch for that.

9. How do you switch to a different branch in Git?

a) git switch
b) git move
c) git jump
d) git hop

Answer:

a) git switch

Explanation:

The git switch <branch-name> command allows you to switch to a different branch. Before Git version 2.23, the common approach was git checkout <branch-name>.

10. Which command merges one branch into another?

a) git merge
b) git join
c) git combine
d) git bind

Answer:

a) git merge

Explanation:

The git merge command integrates changes from one branch into another. This is commonly used when features or bug fixes from one branch need to be brought into the main branch.

11. What is a merge conflict?

a) An error in the Git configuration
b) A disagreement among team members
c) Overlapping changes between branches
d) An issue with remote repository synchronization

Answer:

c) Overlapping changes between branches

Explanation:

A merge conflict occurs when there are changes in the same part of a file in both the current branch and the branch to be merged. Git cannot decide which change should take precedence, so it asks the user to resolve the conflict.

12. Which command is used to clone a remote repository?

a) git copy
b) git replicate
c) git duplicate
d) git clone

Answer:

d) git clone

Explanation:

The git clone command is used to clone (or copy) a remote repository onto your local machine.

13. Which command connects a local repository to a remote server?

a) git link
b) git bind
c) git remote add
d) git connect

Answer:

c) git remote add

Explanation:

The git remote add command connects a local repository to a remote server. This is often followed by a URL representing the location of the remote repository.

14. How do you fetch the latest updates from a remote repository without merging them?

a) git pull
b) git get
c) git fetch
d) git update

Answer:

c) git fetch

Explanation:

The git fetch command fetches updates from a remote repository but doesn’t merge them. It allows you to review changes before integrating them.

15. How do you push changes from a local branch to a remote repository?

a) git send
b) git upload
c) git dispatch
d) git push

Answer:

d) git push

Explanation:

The git push command pushes changes from your local branch to a remote repository. This updates the remote branch with your local changes.

16. What does the HEAD in Git represent?

a) The first commit in the repository
b) The latest commit in the remote repository
c) The currently checked-out commit
d) The base of the current branch

Answer:

c) The currently checked-out commit

Explanation:

In Git, HEAD is a special pointer or reference that points to the currently checked-out commit in the repository.

17. How can you undo the most recent commit?

a) git revert HEAD
b) git reset HEAD~1
c) git undo
d) git back

Answer:

b) git reset HEAD~1

Explanation:

The git reset HEAD~1 command moves the current branch pointer back to the previous commit, effectively undoing the most recent commit. Note that there are different modes (like –soft, –hard) which decide the fate of changes during this operation.

18. Which command is used to stash changes in Git?

a) git hide
b) git keep
c) git reserve
d) git stash

Answer:

d) git stash

Explanation:

The git stash command temporarily saves changes that are not yet ready for a commit, allowing you to switch to another branch without committing the current changes.

19. How do you create a tag in Git?

a) git marker
b) git tag
c) git label
d) git point

Answer:

b) git tag

Explanation:

In Git, the git tag command creates a reference point (or marker) for specific points in your project history. It’s often used to mark release points.

20. Which of the following is not a valid merge strategy in Git?

a) fast-forward
b) recursive
c) octopus
d) squid

Answer:

d) squid

Explanation:

Git supports various merge strategies like fast-forward, recursive, and octopus. “squid” is not a merge strategy in Git.

21. Which command lists all the branches in a Git repository?

a) git list
b) git branches
c) git show-branches
d) git branch

Answer:

d) git branch

Explanation:

The git branch command, when used without any arguments, lists all the branches in a Git repository.

22. What does the git cherry-pick command do?

a) Picks a random commit from history
b) Applies changes from a specific commit to the current branch
c) Deletes a specific commit
d) Merges two unrelated branches

Answer:

b) Applies changes from a specific commit to the current branch

Explanation:

The git cherry-pick command allows you to take a commit from another branch and apply it to your current branch.

23. How do you remove untracked files from your working directory?

a) git clean
b) git erase
c) git purge
d) git remove

Answer:

a) git clean

Explanation:

The git clean command removes untracked files from your working directory, ensuring your workspace is tidy.

24. What is a bare repository in Git?

a) A repository without any commits
b) A repository with no branches
c) A repository without a working directory
d) A repository that can’t be cloned

Answer:

c) A repository without a working directory

Explanation:

A bare repository in Git is a repository that contains only the .git directory and no working directory. It’s typically used for shared repositories and remotes.

25. How do you view the differences between the working directory and the last commit?

a) git view
b) git diff
c) git changes
d) git compare

Answer:

b) git diff

Explanation:

The git diff command shows the differences between the working directory and the last commit. It’s a useful tool to see the changes made before committing them.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top