Quick & Short GIT Question Answer and most used commands !

Wondering what type of questions to ask in GIT Interview ? No need to worry now because here we have posted all interview questions asked in GIT Interview these are not copied from anywhere but real time interview shared by my Friends & Cousins.

1. What is GIT?

  • Git is most popular, open Source, widely used, and an example of distributed version control system (DVCS) used for handling the development of small and large projects in a more efficient and neat manner.
  • It is most Suitable when there are multiple people working on projects as a team and is used for tracking the project changes and efficiently supports the collaboration of the development process.

2. What is GIT Repository ?

A Repository is a file structure where git stores all the project based files. Git can either stores the files on the local or the remote repository.

3. What does Git Clone do ?

The command create a copy(or clone) of an existing git repository. Generally, It is used to get copy of the remote repository to the local repository.


4.What does the command git config do ?

The git config Command is a convenient way to set configuration options for defining the behavior of the repository, User information and preferences, git installation-based configurations, and many such things.

Ex : To setup your name and email address before using git commands, we can run the below commands.
git config –global user.name “<<your_name>>”
git config –global user.email “<<your_email>>”

5. What is conflict & how you will solve this ?

Git Usually handles features merges automatically but sometimes while working in a team environment, there might be cases of conflicts such as :
1. When two separate branches have changes to the same line in a file.
2. A file is deleted in one branch but has been modified in the other.

These conflicts have to be solved manually after discussion with the team as git will not be able to predict what and whose changes have to be given precedence.

6. What is the functionality of git is-tree?

This command returns a tree object representation of the current repository along with the mode and the name of each item and SHA-1 value of the blob.

7. What does git status command do?

git status Command is used for showing the difference between the working directory and the index which is helpful for understanding git in-depth and also keep track of the tracked and non tracked changes.

8.Define “Index” ?

Before making commits to the changes done, the developer is given provision to format and review the files and make innovations to them. All these are done in the common area which is known as ‘Index’ or ‘Staging Area’.

In the above image, the “staged” status indicates the staging area and provides an
opportunity for the people to evaluate changes before committing them.

9. What does git add command do ?

  • This Command adds files and changes to the index of the existing directory.
  • You Can add all changes at once using git add. Command.
  • You can add files one by one specifically using git add <filename> command.
  • You can add contents of a particular folder by using git add / <folder_name> / Command.

10. How you will create a git Repository ?

  • Have git installed in your system.
  • In order to create a git repository, create a folder for the project and then run git init .
  • This will create a .git file in the project folder which indicates that the Repository has been created.

11 . What is git Stash ?

Git Stash can be used in cases where we need to switch in between branches and at the same time not wanting to lose edits in the current branch. Running the git stash command basically pushes the current working directory for other tasks.

12 . What is the command used to delete a branch ?

  • To delete a branch we can simply use the command git branch -d [head].
  • To delete a branch locally, we can simply run the command : git branch -d <local_branch_name>
  • To delete a branch remotely, run the command: git push origin –delete <remote_branch_name>
  • Deleting a branching scenario occurs for multiple reasons. One Such Reason is to get rid of the feature branches once it has been merged into the development branch.

13 . What are difference between Command git remote and git clone ?

git remote Command creates an entity in git config that specifies a name for a particular URL . whereas git clone creates a new git repository by copying an existing one located at the URL.

14. What is git Stash apply Command do ?

  • git stash apply command is used for bringing the work back to the working directory from the stack where the changes were stashed using git stash command.
  • This helps the developers to resume their work where they had last left their work before switching to other branches.

15 . How git pull & git merge is connected to each other ?

git pull = git fetch + git merge

16 . What is difference between Pull request & branch ?

Pull Request : This process is done when there is a need to put a developer’s change into another person’s code branch.

Branch : A branch is nothing but a separate version of the code.

17 . Why do we not call git “pull request” as “push request” ?

Push request is termed so because it is done when the target repository requests us to push our changes to it.

Pull request is named as such due to the fact that the repo requests the target repository to grab(or pull) the changes from it.

18. What is commit object ?

A commit object consists of the following components :

a : A set of files that represents the state of a project at a given point in time.
b : Reference to parent commit objects.
c : A 40 character String termed as SHA-1 name uniquely identifies the commit object.

19. What command helps us know the list of branches merged to master ?

git branch –merged helps to get the list of the branches that have been merged into the current branch.
Note : git branch –no-merged lists the branches that have not been merged to the current branch.

20 . What are the functionalities of git reset –mixed and git merge –abort ?

git reset –mixed command is used for undoing changes of the working directory and the git index.
git merge –abort command is used for stopping the merge process and returning back to the state before the merging occurred.