GIT & GIT HUB Interview Questions & Answers

1)What is GIT?

Ans:GIT is a distributed version control system and source code management (SCM) system with an emphasis to handle small and large projects with speed and efficiency.

2)What are the advantages of using GIT?

Here are some of the most important advantages of Git:

Data redundancy and data replication is possible
It is a highly available service
For one repository you can have only one directory of Git
The network performance and disk utilization are excellent
It is very easy to collaborate on any project
You can work on any sort of project within the Git

3)What are the advantages of Git over SVN?
Ans:Since Git is an open source version control system it lets you run multiple versions of your project so that it shows the changes that are made to the code over time and if needed you can keep a track of the changes that you have made. This means that large number of developers can make their own changes and upload those changes so that the changes can be attributed to the particular developers.

4)What is ‘bare repository’ in Git?


You are expected to tell the difference between a “working directory” and “bare repository”.

A “bare” repository in Git just contains the version control information and no working files (no tree) and it doesn’t contain the special .git sub-directory. Instead, it contains all the contents of the .git sub-directory directly in the main directory itself, where as working directory consist of:

A .git subdirectory with all the Git related revision history of your repo.
A working tree, or checked out copies of your project files.

5)What language is used in Git?

Ans:Instead of just telling the name of the language, you need to tell the reason for using it as well. I will suggest you to answer this by saying:

Git uses ‘C’ language. GIT is fast, and ‘C’ language makes this possible by reducing the overhead of run times associated with high level languages.

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

Ans:Git pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository.

Git fetch is also used for the same purpose but it works in a slightly different way. When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new branch in your local repository. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge. Your target branch will only be updated after merging the target branch and fetched branch. Just to make it easy for you, remember the equation below:

Git pull = git fetch + git merge

7)What is GIT stash?
Ans:The Git stash will take the working directory in the current state and index it to put on the stack at a later stage so that what you get is a clean working directory. This means that if you are in the middle of some task and need to get a clean working directory and simultaneously you want to keep all your current edits then you can use the Git stash.

8)What is GIT stash drop?
Ans:When you are finished with working on the stashed item or want to remove the list then you can use the Git stash drop. This will ensure that the item that is last added by default or any particular item can be removed from the argument.

9)What is the use of a Git clone?
Ans:The Git clone command lets you copy the existing Git repository. If you want to get a copy of the central repository then the best way to do it is using ‘cloning’.

10)How do you find a list of files that has changed in a particular commit?

Ans:For this answer instead of just telling the command, explain what exactly this command will do.

To get a list files that has changed in a particular commit use the below command:

git diff-tree -r {hash}

Given the commit hash, this will list all the files that were changed or added in that commit. The -r flag makes the command list individual files, rather than collapsing them into root directory names only.

The output will also include some extra information, which can be easily suppressed by including two flags:

git diff-tree –no-commit-id –name-only -r {hash}

Here –no-commit-id will suppress the commit hashes from appearing in the output, and –name-only will only print the file names, instead of their paths.

11)What is the function of ‘git config’?

First tell why we need ‘git config‘.

Git uses your username to associate commits with an identity. The git config command can be used to change your Git configuration, including your username.

Now explain with an example.

Suppose you want to give a username and email id to associate commit with an identity so that you can know who has made a particular commit. For that I will use:

12)What are the constituents of the commit object contain?


the state of a project at a given point of time is contained in a set of files
Parent object commit references
A 40-character string that uniquely identifies the commit object called a SHAI name

13)Why do we need branching in GIT?

Ans:With the help of branching you can have your own branch and you can also jump between the various branches. You can go to your previous work while at the same time keeping your recent work intact.

14)What is the regular way for branching in GIT?

Ans:The best way to create a branch in GIT is to have one ‘main’ branch and then create another branch for implementing the changes that you want to make. This is extremely useful when there are a large number of developers working on a single project.

15)State a way to create a new branch in Git?

Ans:If you want to create a new feature into the main branch then you can use the command ‘git merge’ or ‘git pull’.

16)How will you know in Git if a branch has already been merged into master?

Ans:To know if a branch has been merged into master or not you can use the below commands:

git branch –merged It lists the branches that have been merged into the current branch.
git branch –no-merged It lists the branches that have not been merged.

17)How do you define a ‘conflict’ in git?

Ans:If you want to merge a commit there is a change in one place and same change already exists then while merging the Git will not be able to predict which is the change that needs to be taken precedence.

18)How to resolve a conflict in Git?

Ans:If you want to resolve a conflict in Git then you need to edit the files for fixing the conflicting changes and then you can run “git add” to add the resolved files and after that you can run the ‘git commit’ for committing the repaired merge.

19)Mention some of the best graphical GIT client for LINUX?


Some of the best GIT client for LINUX is

a) Git Cola

b) Git-g

c) Smart git

d) Giggle

e) Git GUI

f) qGit

20)What is Subgit? Why to use Subgit?


‘Subgit’ is a tool for a smooth, stress-free SVN to Git migration. Subgit is a solution for a company -wide migration from SVN to Git that is:

a) It is much better than git-svn

b) No requirement to change the infrastructure that is already placed

c) Allows to use all git and all sub-version features

d) Provides genuine stress –free migration experience.

21)What is the function of ‘git diff ’ in git?

Ans:‘git diff ’ shows the changes between commits, commit and working tree etc.

22) What is ‘git status’ is used for?

Ans:As ‘Git Status’ shows you the difference between the working directory and the index, it is helpful in understanding a git more comprehensively.

23)What is the function of ‘git checkout’ in git?

Ans:A ‘git checkout’ command is used to update directories or specific files in your working tree with those from another branch without merging it in the whole branch.

24)What is the use of ‘git log’?

Ans:To find specific commits in your project history- by author, date, content or history ‘git log’ is used.

25)What is git Is-tree?

Ans:‘git Is-tree’ represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.

For more  Click Here

For Course Content  Click Here