Top 30 GIT Questions and Answers with Explanation 2022 [updated]

Git is used in devops for version control by many big organizations across the world. It helps individual developers keep track of changes as they work on different features in the same project, and helps teams organize their code. Git is a free software distributed under the terms of the GNU General Public License version 2. We have try to collect all GIT Questions and Answers which might help you to get through your next interview.

GIT Questions and Answers

Git comes with built-in GUI tools (git-guigitk), but there are several third-party tools for users looking for a platform-specific experience.

Git Download Link

Features of Git

  • Tracks history
  • Free and open source
  • Supports non-linear development
  • Creates backups
  • Scalable
  • Supports collaboration
  • Branching is easier
  • Distributed development

GIT Questions and Answers MCQs with Explanation

Question:1 Which command would you use to view the history of commits?

a) git view history

b) git show history

c) git log

d) git show commits

Correct Answer: git log

Question:2 How to display only the names of the changed files?

a) git diff –name-only

b) git log

c) git status

d) None of the options

Correct Answer: git diff –name-only

Question:3 Which command can you use to update remote refs with local refs?

a) git push

b) git fetch

c) git pull

d) git update

Correct Answer: git push

Question:4 Which command shows the difference between the working directory and the index or staging area?

a) git status

b) git diff

Correct Answer: git diff

Question:5 Which type of remote URL does not require your user-name and password while for cloning or pushing?

a) SSH url

b) Https Url

Correct Answer: SSH url

Question:6 When you run git fetch from your local repo, it will update your local changes in working area?

a) True – It fetches the latest changes and merges with the local changes

b) False – It updates local repo only and does not affect the working area

Correct Answer: False – It updates local repo only and does not affect the working area

Question:7 When you run git fetch from my local repo, will it update your local code and target branch?

a) Yes, the command will download new commits from remote and merge to the target branch

b) No, the command will only download the new commits and keep them in a separate branch in local repo

Correct Answer: No, the command will only download the new commits and keep them in a separate branch in local repo

Question:8 What is the command to store uncommitted temporarily?

a) git commit

b) git tempstore

c) git stash

d) git store

Correct Answer: git stash

Question:9 What does the command git checkout -b branchname do?

a) Creates a new branch and switches to this new branch

b) Switches from the current branch to the new branch

c) Deletes the new branch

d) Commits the new branch

Correct Answer: Creates a new branch and switches to this new branch

Question:10 What is the Git command to create a branch?

a) git invoke branch branchname

b) git add branch branchname

c) git create branch branchname

d) git branch branchname

Correct Answer: git branch branchname

Question:11 What does the command git checkout branchname do?

a) Adds the new branch

b) Switches from main branch to the new branch

c) Commits the new branch

d) Deletes the new branch

Correct Answer: Switches from main branch to the new branch

Question:12 What is the Git command to skip staging and commit the changes directly?

a) git skip stage

b) git commit

c) git commit -a -m “message”

d) git add changes

Correct Answer: git commit -a -m “message”

Question:13 A tag in Git context is a __.

a) Keyword

b) Reference to a specific commit

c) Search String

Correct Answer: Reference to a specific commit

Question:14 How can you fix a broken commit?

a) git reset

b) git commit –amend

c) git fix

d) git rebase

Correct Answer: git commit –amend

Question:15 Developers A and B are building the same feature on feature/X branch. Developer B made some changes and pushed to the remote. How can developer A get the changes in the local repo code and build on top of developer B’s work?

a) git checkout

b) git log

c) git pull

d) git push

Correct Answer: git pull

Question:16 Developer A has done some changes in the subproject and pushed it. Developer B can pull those changes using __.

a) git fetch origin

b) git submodule update

c) git pull origin

d) git submodule add

Correct Answer: git submodule update

Question:17 Which of the following creates new commit when you pull new changes from master to the feature branch?

a) git rebase master

b) git merge master

c) git pull origin master

Correct Answer: git merge master

Question:18 How to delete unpublished Git commits and get rid of them permanently?

a) git reset –hard

b) git revert

c) git reset –soft

Correct Answer: git reset –hard

Question:19 Which of the following best describes Git?

a) Access Control System

b) Version Control System

c) Role Control System

d) None of the options

Correct Answer: Version Control System

Question:20 What does the command git add . do?

a) Adds all the files to repo

b) Adds all the files to the staging area

c) Adds all the files to the local directory

d) None of the options

Correct Answer: Adds all the files to the staging area

Question:21 Git is a _____.

a) Distributed Version Control System

b) Centralized Version Control System

c) Centrally Distributed System

d) None of the options

Correct Answer: Distributed Version Control System

Question:22 What does the command Git reset –- soft HEAD^ perform?

a) Moves commit to one after current head

b) Moves commit to one before current head

c) Moves commit to the first head

d) None of the options

Correct Answer: Moves commit to one before current head

Question:23 What is the Git command to blow away all the changes in a file in the working area, since the previous commit?

a) git status filename

b) git log filename

c) git checkout filename

d) git rm filename

Correct Answer: git checkout filename

Question:24 What is the command to reset your index as well as the working directory to the state of your last commit?

a) git clean

b) git reset

c) git revert

d) git checkout

Correct Answer: git reset

Question:25 How can you temporarily switch to a different commit?

a) git reset commitSHA

b) git commit commitSHA

c) git checkout commitSHA

d) all the above options

Correct Answer: git checkout commitSHA

Question:26 What is the Git command to view the last 3 commits in one line ?

a) git show log -3

b) git last 3 commits

c) git log

d) git log -–oneline -3

Correct Answer: git log -–oneline -3

Question:27 What is the Git command to view all the commits since 1st January 2017 ?

a) show git log since Jan 1 2017

b) git log -–since=”2017-01-01”

c) git log

d) None of the options

Correct Answer: git log -–since=”2017-01-01”

Question:28 What is the Git command to view all the changes since the last commit ?

a) git clean

b) git status

c) git changes

d) git commit

Correct Answer: git status

Question:29 What is the command to delete a branch in your remote repository?

a) git delete branchname

b) git branch -d branchname

c) git push origin -d branchname

d) None of the options

Correct Answer: git push origin -d branchname

Question:30 What is a good practice to follow when you want to backup a local branch?

a) Push to remote repo

b) Move to another PC

c) Create another copy

d) None of the options

Correct Answer: Push to remote repo

About Author


After years of Technical Work, I feel like an expert when it comes to Develop wordpress website. Check out How to Create a Wordpress Website in 5 Mins, and Earn Money Online Follow me on Facebook for all the latest updates.