Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What does git add command do?

Answer»
  • 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 <file_name> command.
     
  • You can add CONTENTS of a particular folder by using git add /<folder_name>/ command.
2.

Define “Index”.

Answer»

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.

3.

What does git status command do?

Answer»

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.

4.

What is the functionality of git ls-tree?

Answer»

This COMMAND returns a tree object representation of the CURRENT repository ALONG with the mode and the name of each ITEM and the SHA-1 value of the BLOB.

5.

What is a conflict?

Answer»
  • Git usually handles FEATURE 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.

Can you explain head in terms of git and also tell the number of heads that can be present in a repository?

Answer»
  • A head is nothing but a reference to the last commit OBJECT of a branch.
  • For every repository, there will always be a default head referred to as “master” or now “MAIN” (as per GitHub) but there is no restriction to the count of heads available. In other words, it can have any number of heads.
  • Usages:

    - To GO or checkout to 1 commit before the latest commit, we use git checkout HEAD~1

    - To uncommit the last 3 commits without losing the changes, we first run git reset HEAD~3. Then we can see the changes made in the last 3 commits and then update it manually and commit it finally.

    - In order to uncommit the last 3 commits and also remove the changes, we can run the command: git reset --hard HEAD~3. This command will COMPLETELY remove all the changes.

    - To look into the changes made in the last 3 commits, we can run git diff HEAD~3

    - To make a new commit by reverting the last 3 commits, we can run the command: git revert --no-commit HEAD~3...HEAD
7.

What does the command git config do?

Answer»

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. 

For example:
To set up your name and email address before using git commands, we can run the below commands:

  • git config --global
    user.name
    “&LT;<your_name>>”
     
  • git config --global user.email “<<your_email>>”
8.

What does git clone do?

Answer»

The command creates a copy (or clone) of an EXISTING git repository. Generally, it is USED to GET a copy of the remote repository to the LOCAL repository.

9.

What is a git repository?

Answer»

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.

10.

What is a version control system (VCS)?

Answer»

A VCS keeps TRACK of the contributions of the developers working as a team on the projects. They maintain the history of code changes done and with project evolution, it gives an UPPER hand to the developers to INTRODUCE new code, fixes bugs, and run tests with confidence that their previously working copy could be restored at any moment in case THINGS go wrong.