0% found this document useful (0 votes)
3K views26 pages

MCQ Git

The document provides answers to multiple choice questions about Git commands. It covers topics like adding commit messages, committing all changes with a message, the order of git add and git commit, checking file status with git status, adding new files with git add, showing config parameters with git config --list, checking out the master branch with git checkout master, undoing a commit with git revert, permanently cancelling a commit with git reset, and creating and checking out a new branch with git checkout -b.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views26 pages

MCQ Git

The document provides answers to multiple choice questions about Git commands. It covers topics like adding commit messages, committing all changes with a message, the order of git add and git commit, checking file status with git status, adding new files with git add, showing config parameters with git config --list, checking out the master branch with git checkout master, undoing a commit with git revert, permanently cancelling a commit with git reset, and creating and checking out a new branch with git checkout -b.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

1. How do I add a message to a commit?


$ git message "Fix error in xxxx"

$ git add "Fix error in xxxx"

$ git commit "Fix error in xxxx"

$ git commit -m "Fix error in xxxx"
Answer
 D
 

 
2. What is the correct syntax for committing all changes with a message?

$ git message -am "Fix error in xxxx"

$ git add -a "Fix error in xxxx"

$ git commit -a "Fix error in xxxx"

$ git commit -am "Fix error in xxxx"
Answer
 D
 

 
3. Which comes first _____?

$ git add

$ git commit
Answer
 A
 

 
4. You can type “git status” at any time in a directory controlled by git to check
the status of your files.
A True
B False
Answer
 A
 

 
5. We have just created a new file called “home.html”. Which of the following
will add this file so that we can commit it in git?

$ git add home.html

$ git add new

$ git add -a home.html

$ git git commit home.html
Answer
 A
 

 
6. Which of the following commands used to show all parameters in git?

$ git config --list

$ git config -a

$ git config --all

$ git config --parameters --list
Answer
 A
 

 
7. Which of the following commands used to return to the master branch?

$ git checkout origin

$ git checkout -b master

$ git checkout master

$ git checkout branche
Answer
 C
 

 
8. Which of the following commands used to undo a commit?

$ git reset <commit>

$ git revert <commit>

$ git reset --hard origin/master

$ git init
Answer
 B
 

 
9. Which of the following commands used to permanently cancel a commit?

$ git reset <commit>

$ git revert <commit>

$ git reset --hard origin/master

$ git init
Answer
 A
 

 
10. How to create a new branch and switch to it directly?

$ git checkout <branch-name>

$ git branch <branch-name>

$ git checkout -b <branch-name>

$ git branch -new <branch-name>
Answer
 C
 
MCQ Practice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to
prepare for tests and interviews.READ MORE
Git MCQ Set 1
1. What is full form of VCS?

A. Version Configuration System

B. Version Consolidated Solutions

C. Version Configuration Solutions

D. Version Control System

Explanation
Correct Option :D.

2. Git is a __________

A. Distributed version control system

B. Centralized version control system

C. Localized version control system

D. All of the above

Explanation
Correct Option :A.

3. Which of the following is true about Centralized version control system?

A. It does not rely on the central server

B. It is victim to single point of failure

C. It rely on the central server

D. Both B & C

Explanation
Correct Option :D.

4. Which of the following is true about Git?


1. Git does not rely on the central server.
2. Git require network connection only to publish your changes and take the latest changes.
3. Every git checkout is a full backup of the server repository.

A. Only 1 & 2

B. Only 1 & 3

C. Only 2 & 3

D. All of the above

Explanation
Correct Option :D.

o R
5. The files that can be committed are always present in git 

A. working directory

B. staging area

C. unstaged area

D. Anywhere, there is no barrier

Explanation
Correct Option :B.

6. Git can be used for which project?

A. Java enterprise project

B. .Net project

C. File version management

D. All of the above

Explanation
Correct Option :D.

7. Which of the following terminology is not related to git?

A. staging area

B. fork

C. branch

D. stem

Explanation
Correct Option :D.

8. Which of the following is not true about git?

A. By default Git has a master branch

B. Git clone operation creates the instance of the repository.

C. Pull operation copies the changes from a local repository to remote repository

D. All of the above

Explanation
Correct Option :C.
Git MCQ Set 2
1. Which of the following is example of distributed version control?

A. Git

B. Mercurial

C. SVN

D. Both A & B

Explanation
Correct Option :D.

2. Who created Git?

A. Dennis Ritchie

B. Linus Torvalds

C. Linus Babbage

D. James Gosling

Explanation
Correct Option :B.

3. Which of the following are the stages in which your git file can reside?

A. modified

B. staged

C. committed

D. Any of the above

Explanation
Correct Option :D.

4. Git command that lets you get and set configuration variables that control all aspects of how Git looks and operates is

A. git config

B. git --version

C. git init

D. All of the above

Explanation
Correct Option :A.
5. Which of the following is correct git command to set your username during git initial setup? 

A. git config --global user.name "Rajneesh"

B. git config --global user "Rajneesh"

C. git init config --global user.name "Rajneesh"

D. git --global user.name "Rajneesh"

Explanation
Correct Option :A.

6. Git command to list all the settings Git can find at any point of time is

A. git config

B. git config --settings

C. git --list

D. git config --list

Explanation
Correct Option :D.

7. To get the comprehensive manual page (manpage) help for any of the Git commands we can use

A. git help

B. git --help

C. man git-

D. Any of the above

Explanation
Correct Option :D.

8. Git command that helps us initialize git repository for the project (folder) that we intend to track using version control
system Git is

A. git config

B. git init

C. git add .

D. None of the above

Explanation
Correct Option :B.
Git MCQ Set 2
1. Which of the following is example of distributed version control?

A. Git

B. Mercurial

C. SVN

D. Both A & B

Explanation
Correct Option :D.

2. Who created Git?

A. Dennis Ritchie

B. Linus Torvalds

C. Linus Babbage

D. James Gosling

Explanation
Correct Option :B.

3. Which of the following are the stages in which your git file can reside?

A. modified

B. staged

C. committed

D. Any of the above

Explanation
Correct Option :D.

4. Git command that lets you get and set configuration variables that control all aspects of how Git looks and operates is

A. git config

B. git --version

C. git init

D. All of the above

Explanation
Correct Option :A.
5. Which of the following is correct git command to set your username during git initial setup? 

A. git config --global user.name "Rajneesh"

B. git config --global user "Rajneesh"

C. git init config --global user.name "Rajneesh"

D. git --global user.name "Rajneesh"

Explanation
Correct Option :A.

6. Git command to list all the settings Git can find at any point of time is

A. git config

B. git config --settings

C. git --list

D. git config --list

Explanation
Correct Option :D.

7. To get the comprehensive manual page (manpage) help for any of the Git commands we can use

A. git help

B. git --help

C. man git-

D. Any of the above

Explanation
Correct Option :D.

8. Git command that helps us initialize git repository for the project (folder) that we intend to track using version control
system Git is

A. git config

B. git init

C. git add .

D. None of the above

Explanation
Correct Option :B.
GIT Interview Questions
1) What is GIT?

Git is an open source distributed version control system and source code management (SCM) system with
an insistence to control small and large projects with speed and efficiency.

2) Which language is used in Git?

Git uses 'C' language. Git is quick, and 'C' language makes this possible by decreasing the overhead of run
times contained with high-level languages.

3) What is a repository in Git?

A repository consists of a list named .git, where git holds all of its metadata for the catalog. The content of
the .git file is private to Git.

4) What is 'bare repository' in Git?

A "bare" repository in Git includes the version control information and no working files (no tree), and it
doesn?t include the special. git sub-directory. Instead, it consists of all the contents of the .git sub-
directory directly in the main directory itself, whereas working list comprises of:

43.5M

955

Features of Java - Javatpoint

1. A .git subdirectory with all the Git associated revision history of your repo.
2. A working tree, or find out copies of your project files.

5) What is the purpose of GIT stash?

GIT stash takes the present state of the working file and index and puts in on the stack for next and gives
you back a clean working file. So in case if you are in the middle of object and require to jump over to the
other task, and at the same time you don't want to lose your current edits, you can use GIT stash.
6) What is GIT stash drop?

When you are done with the stashed element or want to delete it from the directory, run the git 'stash
drop' command. It will delete the last added stash item by default, and it can also remove a specific topic
if you include as an argument.

7) What are the advantages of using GIT?

Here are some of the essential advantages of Git:

o Data repetition and data replication is possible


o It is a much applicable service
o For one depository you can have only one directory of Git
o The network performance and disk application are excellent
o It is effortless to collaborate on any project
o You can work on any plan within the Git

8) What is the function of 'GIT PUSH' in GIT?

'GIT PUSH' updates remote refs along with related objects

9) Why do we require branching in GIT?

With the help of branching, you can keep your branch, and you can also jump between the different
branches. You can go to your past work while at the same time keeping your recent work intact.

10) What is the purpose of 'git config'?

The 'Git config' is a great method to configure your choice for the Git installation. Using this command,
you can describe the repository behavior, preferences, and user information.
11) What is the definition of "Index" or "Staging Area" in GIT?

When you are making the commits, you can make innovation to it, format it and review it in the common
area known as 'Staging Area' or 'Index'.

12) What is a 'conflict' in git?

A 'conflict' appears when the commit that has to be combined has some change in one place, and the
current act also has a change at the same place. Git will not be easy to predict which change should take
precedence.

13) What is the difference between git pull and git fetch?

Git pull command pulls innovation or commits from a specific branch from your central repository and
updates your object branch in your local repository.

Git fetch is also used for the same objective, but it works in a slightly different method. When you behave
a git fetch, it pulls all new commits from the desired branch and saves it in a new branch in your local
repository. If you need to reflect these changes in your target branch, git fetch should be followed with a
git merge. Your target branch will only be restored after combining the target branch and fetched branch.
To make it simple for you, remember the equation below:

Git pull = git fetch + git merge

14) How to resolve a conflict in Git?

If you need to resolve a conflict in Git, edit the list for fixing the different changes, and then you can run
"git add" to add the resolved directory, and after that, you can run the 'git commit' for committing the
repaired merge.

15) What is the purpose of the git clone?

The git clone command generates a copy of a current Git repository. To get the copy of a central
repository, 'cloning' is the simplest way used by programmers.
16) What is git pull origin?

pull is a get and a consolidation. 'git pull origin master' brings submits from the master branch of the
source remote (into the local origin/master branch), and then it combines origin/master into the branch
you currently have looked out.

17) What does git commit a?

Git commits "records changes to the storehouse" while git push " updates remote refs along with
contained objects" So the first one is used in a network with your local repository, while the latter one is
used to communicate with a remote repository.

18) Why GIT better than Subversion?

GIT is an open source version control framework; it will enable you to run 'adaptations' of a task, which
demonstrate the changes that were made to the code over time also it allows you keep the backtrack if
vital and fix those changes. Multiple developers can check out, and transfer changes, and each change can
then be attributed to a particular developer.

19) Explain what is commit message?

Commit message is a component of git which shows up when you submit a change. Git gives you a
content tool where you can enter the adjustments made to a commit.

20) Why is it desirable to create an additional commit rather than amending an


existing commit?

There are couples of reason

1. The correct activity will devastate the express that was recently saved in a commit. If only the
commit message gets changed, that's not a problem. But if the contents are being modified,
chances of excluding something important remains more.
2. Abusing "git commit- amends" can cause a small commit to increase and acquire inappropriate
changes.
21) What does 'hooks' comprise of in Git?

This index comprises of Shell contents which are enacted after running the relating git commands. For
instance, Git will attempt to execute the post-commit content after you run a commit.

22) What is the distinction between Git and Github?

A) Git is a correction control framework, a tool to deal with your source code history.

GitHub is a hosting function for Git storehouses.

GitHub is a website where you can transfer a duplicate of your Git archive. It is a Git repository hosting
service, which offers the majority of the distributed update control and source code management (SCM)
usefulness of Git just as including its features.

23) In Git, how would you return a commit that has just been pushed and made
open?

There can be two answers to this question and ensure that you incorporate both because any of the
below choices can be utilized relying upon the circumstance:

Remove or fix the bad document in another commit and push it to the remote repository. This is a unique
approach to correct a mistake. Once you have necessary changes to the record, commit it to the remote
repository for that I will utilize

git submit - m "commit message."

Make another commit that fixes all changes that were made in the terrible commit. to do this, I will utilize
a command

git revert <name of bad commit>

24) What does the committed item contain?

Commit item contains the following parts; you should specify all the three present below:

A set of records, representing to the condition of a task at a given purpose of time

References to parent commit objects

An SHAI name, a 40 character string that uniquely distinguishes the commit object.
25) Describing branching systems you have utilized?

This question is a challenge to test your branching knowledge with Git along these lines, inform them
regarding how you have utilized branching in your past activity and what reason does it serves, you can
refer the below mention points:

Feature Branching:

A component branch model keeps the majority of the changes for a specific element within a branch. At
the point when the item is throughout tested and approved by automated tests, the branch is then
converged into master.

Task Branching

In this model, each assignment is actualized on its branch with the undertaking key included in the branch
name. It is anything but difficult to see which code actualizes which task, search for the task key in the
branch name.

Release Branching

Once the create branch has procured enough features for a discharge, you can clone that branch to frame
a Release branch. Making this branch begins the following discharge cycle so that no new features can be
included after this point, just bug fixes, documentation age, and other release oriented assignments ought
to go in this branch. When it is prepared to deliver, the release gets converged into master and labeled
with a form number. Likewise, it should be converged once again into creating a branch, which may have
advanced since the release was started.

At last, disclose to them that branching methodologies fluctuate starting with one association then onto
the next, so I realize essential branching activities like delete, merge, checking out a branch, etc.

26) By what method will you know in Git if a branch has just been combined into
master?

The appropriate response is immediate.

To know whether a branch has been merged into master or not you can utilize the below commands:

git branch - merged It records the branches that have been merged into the present branch.

git branch - no merged It records the branches that have not been merged.
27) How might you fix a messed up submit?

To fix any messed up commit, you will utilize the order "git commit?correct." By running this direction, you
can set the wrecked commit message in the editor.

28) Mention the various Git repository hosting functions.

The following are the Git repository hosting functions:

o Pikacode
o Visual Studio Online
o GitHub
o GitEnterprise
o SourceForge.net

29) Mention some of the best graphical GIT customers for LINUX?

Some of the best GIT customer for LINUX is

a. Git Cola
b. Smart git
c. Git-g
d. Git GUI
e. Giggle
f. qGit

30) What is Subgit? Why use it?

'Subgit' is a tool that migrates SVN to Git. It is a stable and stress-free migration. Subgit is one of the
solutions for a company-wide migration from SVN to Git that is:

a. It is much superior to git-svn


b. No need to change the infrastructure that is already placed.
c. It allows using all git and all sub-version features.
d. It provides stress ?free migration experience.

Here are the Git commands which are being covered:


 git config
 git init
 git clone
 git add
 git commit
 git diff
 git reset
 git status
 git rm
 git log
 git show
 git tag
 git branch
 git checkout
 git merge
 git remote
 git push
 git pull
 git stash

So, let's get started!

Git Commands
git config
Usage: git config –global user.name “[name]”   
Usage: git config –global user.email “[email address]”   
This command sets the author name and email address respectively to be used with your
commits.

git init
Usage: git init [repository name]
 
This command is used to start a new repository.

git clone
Usage: git clone [url]  
This command is used to obtain a repository from an existing URL.

git add
Usage: git add [file]  
This command adds a file to the staging area.

Usage: git add *  


This command adds one or more to the staging area.

git commit
Usage: git commit -m “[ Type in the commit message]”   
This command records or snapshots the file permanently in the version history.

Usage: git commit -a  


This command commits any files you’ve added with the git add command and also commits
any files you’ve changed since then.

git diff
Usage: git diff  
This command shows the file differences which are not yet staged.

 Usage: git diff –staged 


This command shows the differences between the files in the staging area and the latest
version present.

Usage: git diff [first branch] [second branch]   


This command shows the differences between the two branches mentioned.

git reset
Usage: git reset [file]  
This command unstages the file, but it preserves the file contents.

Usage: git reset [commit]  


This command undoes all the commits after the specified commit and preserves the
changes locally.

Usage: git reset –hard [commit]  This command discards all history and goes back to the
specified commit.

git status
Usage: git status  
This command lists all the files that have to be committed.

git rm
Usage: git rm [file]  
This command deletes the file from your working directory and stages the deletion.

git log
Usage: git log  
This command is used to list the version history for the current branch.

Usage: git log –follow[file]  


This command lists version history for a file, including the renaming of files also.
git show
Usage: git show [commit]  
This command shows the metadata and content changes of the specified commit.
git tag
Usage: git tag [commitID]  
This command is used to give tags to the specified commit.

git branch
Usage: git branch  
This command lists all the local branches in the current repository.
Usage: git branch [branch name]  
This command creates a new branch.

Usage: git branch -d [branch name]  


This command deletes the feature branch.

git checkout
Usage: git checkout [branch name]  
This command is used to switch from one branch to another.

Usage: git checkout -b [branch name]  


This command creates a new branch and also switches to it.

git merge
Usage: git merge [branch name]  
This command merges the specified branch’s history into the current branch.

git remote
Usage: git remote add [variable name] [Remote Server Link]   
This command is used to connect your local repository to the remote server.

git push
Usage: git push [variable name] master  
This command sends the committed changes of master branch to your remote repository.

Usage: git push [variable name] [branch]   


This command sends the branch commits to your remote repository.

Usage: git push –all [variable name]  


This command pushes all branches to your remote repository.

Usage: git push [variable name] :[branch name]   


This command deletes a branch on your remote repository.

git pull
Usage: git pull [Repository Link]  
This command fetches and merges changes on the remote server to your working
directory.

git stash
Usage: git stash save  
This command temporarily stores all the modified tracked files.

Usage: git stash pop  


This command restores the most recently stashed files.

Usage: git stash list  


This command lists all stashed changesets.

Usage: git stash drop  


This command discards the most recently stashed changeset.

You might also like