Git Interview Questions And Answers

git interview questions and answers   Top 21 Git Interview Questions And Answers

1) What is version control System?

It is a system that records changes done to a file or set of files over a time period so that you can recall specific versions later whenever needed.


2) What are the benefits of Version Control System?

Following are the benefits of Version Control System:

● It allows you to revert selected files back to a previous state in case of any issue.
● It allows to revert the entire project back to a previous state if there are some serious issues.
● Allows to compare changes over time.
● Allows to check who last modified something that might be causing a problem.
● One of the key benefit is that we can easily identify who introduced an issue and when.


3) What is Centralized Version Control Systems?

These are the centralized systems that have single server that contains all the versioned files, and a number of clients that check out files from that central place. For many years these centralized systems are being used by the developers all across the world. Example Subversion, Perforce etc.


4) What are the benefits of Centralized Version Control System like Subversion?

Following are the benefits of Centralized Version Control System:

● Administrators have fine-grained control over who can do what.
● It is easy to maintain the code in central place.
● Its easy to administer the central code repository.


5) What is Distributed Version Control Systems?

In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don't just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. Thus, if any server dies, and these systems were collaborating via that server, any of the client repositories can be copied back up to the server to restore it. Every clone is really a full backup of all the data.


6) How Git stores its data?

Git thinks of its data more like a series of snapshots of a miniature file system. With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn't store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.


7) How Git has Integrity?

Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it's impossible to change the contents of any file or directory without Git knowing about it. This functionality is built into Git at the lowest levels and is integral to its philosophy. You can't lose information in transit or get file corruption without Git being able to detect it.


8) Which mechanism Git is using for check sum?

The mechanism that Git uses for this checksumming is called a SHA-1 hash. This is a 40-character string composed of hexadecimal characters (0-9 and a-f) and calculated based on the contents of a file or directory structure in Git.


9) How Git stores data in database?

Git stores everything in its database not by file name but by the hash value of its contents.


10) In Git, what are the three main states that your files can reside in?

Git has three main states that your files can reside in:

● Committed
● Modified
● Staged

Committed means that the data is safely stored in your local database.
Modified means that you have changed the file but have not committed it to your database yet.
Staged means that you have marked a modified file in its current version to go into your next commit snapshot.


11) Which are the three main sections of a Git project?

Following are the three main sections of Git project:

● Git directory
● Working tree
● Staging area


12) What is Git directory?

It is the place where Git stores the metadata and object database for your project.

This is the most important part of Git, and it is what is copied when you clone a repository from another computer.


13) What is working tree in Git?

The working tree is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.


14) What is staging area in Git?

The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit.


15) What is index in Git?

It is nothing but the staging area which stores information about what will go into your next commit.


16) What is the basic Git workflow?

The basic Git workflow goes something like this:

1 You modify files in your working tree.
2 You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area.
3 You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.


17) How to install Git in Linux using command line?

Here is the syntax of the command to install Git in Linux:

$ sudo dnf install git-all</pre>


18) How to install Git in Ubuntu using command line?

Here is the syntax of the command to install Git in Ubuntu:

$ sudo apt install git-all</pre>


19) How to install Git on Mac?

Here is the syntax of the command to install Git on Mac:

$ git --version</pre>


20) What is Git config?

It is a tool that lets you get and set configuration variables that control all aspects of how Git looks and operates.


21) How to initialize the Git repository?

Here is the syntax of the command to initialize the Git repository:

$ git init</pre>