Prodigious Git Interview Question-Answer

Q.1 Which of the following best describes Git?

       A. Access Control System

       B. Version Control System

       C. Role Control System

       D. None of the options

Ans : Version Control System


Q.2 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

Ans : Adds all the files to the staging area


Q.3 Git is a _________________.

       A. Distributed Version Control System

       B. Centralized Version Control System

       C. Centrally Distributed System

       D. None of the options

Ans : Distributed Version Control System


Q.4 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

Ans : git log


Q.5 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

Ans : git diff –name-only


Q.6 Which command can you use to update remote refs with local refs?

       A. git push

       B. git fetch

       C. git pull

       D. git update

Ans : git push


Q.7 Which command shows the difference between the working directory and the index or staging area?

       A. git status

       B. git diff

Ans : git diff


Q.8 Which type of remote URL does not require your user-name and password while for cloning or pushing?

       A. SSH url

       B. Https Url

Ans : SSH url


Q.9 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

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


Q.10 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

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


Q.11 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

Ans : Creates a new branch and switches to this new branch


Q.12 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

Ans : git branch branchname


Q.13 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

Ans : git push origin -d branchname


Q.14 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

Ans : Push to remote repo


Q.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

Ans : git pull


Q.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

Ans : git submodule update


Q.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

Ans : git merge master


Q.18 How to delete unpublished Git commits and get rid of them permanently?

       A. git reset –hard

       B. git revert

       C. git reset –soft

Ans : git reset –hard


Q.19 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

Ans : Moves commit to one before current head


Q.20 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

Ans : git checkout filename


Q.21 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

Ans : git reset


Q.22 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

Ans : git checkout commitSHA


Q.23 What is the command to store uncommitted temporarily?

       A. git commit

       B. git tempstore

       C. git stash

       D. git store

Ans : git stash


Q.24 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

Ans : git log -–oneline -3


Q.25 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

Ans : git log -–since=”2017-01-01”


Q.26 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

Ans : git status


Q.27 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

Ans : Switches from main branch to the new branch


Q.28 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

Ans : git commit -a -m “message”


Q.29 A tag in Git context is a ______.

       A. Keyword

       B. Reference to a specific commit

       C. Search String

Ans : Reference to a specific commit


Q.30 How can you fix a broken commit?

       A. git reset

       B. git commit –amend

       C. git fix

       D. git rebase

Ans : git commit –amend


Leave a Comment