0% found this document useful (0 votes)
26 views

GIT Interview

git

Uploaded by

raghuhera79
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

GIT Interview

git

Uploaded by

raghuhera79
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

GIT

 Git is the 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.
 With the help of the versioning system, the developer can identify who
has made what changes and then run tests and fix bugs if any and then
do necessary feature implementation. In case of any unforeseen
circumstances, the code can be reverted to any of the previously working
versions thereby saving huge efforts.

1. What is a version control system (VCS)?

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.

2. What is a 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 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.

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.

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
“<<your_name>>”

 git config --global user.email “<<your_email>>”

7. What is the functionality of git ls-tree?

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.

8. 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.

9. 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’.

10. 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
<file_name> command.

 You can add contents of a particular folder by using git add


/<folder_name>/ command.

How will you create a git repository?

 Have git installed in your system.


 Then in order to create a git repository, create a folder for the project and
then run git init.
 Doing this will create a .git file in the project folder which indicates that
the repository has been created.

13. Tell me something about 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 state
and index to the stack for future use and thereby providing a clean working
directory for other tasks.

14. 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.

15. What differentiates between the commands git remote and git
clone?

git remote command creates an entry 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.

16. What does git stash apply command do?

 git stash apply command is used for bringing the works 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.

17. Differentiate between git pull and git fetch.

git pull git fetch


This command is also used for a similar
purpose but it follows a two step process:
1. Pulls all commits and changes from
This command pulls new changes
desired branch and stores them in a new
from the currently working branch
branch of the local repository.
located in the remote central
current
repository.
2. For changes to be reflected in the
current / target branch, git fetch should
be followed by git merge command.
git pull = git fetch + git merge

18. Can you give differences between “pull request” and “branch”?

pull request branch


This process is done when there is a need to put a A branch is nothing but a
developer’s change into another person’s code separate version of the
branch. code.
19. 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.

20. Can you tell the difference between Git and GitHub?

Git GitHub
This is a distributed version control
This is a cloud-based source
system installed on local machines which
code repository developed
allow developers to keep track of commit
by using git.
histories and supports collaborative work.
This was acquired by
This is maintained by “The Linux Foundation”.
“Microsoft”
GitLab, Atlassian BitBucket, etc
SVN, Mercurial, etc are the competitors
are the competitors.

 GitHub provides a variety of services like forking, user management, etc


along with providing a central repository for collaborative work.

21. What do the git diff and git status commands do?

git diff git status


This shows the This shows the difference between the
changes between commits, working directory and index that is essential
working trees, etc. in understanding git in depth.

 git diff works in a similar fashion to git status with the only difference
of showing the differences between commits and also between the
working directory and index.

What has to be run to squash multiple commits (last N) into a single


commit?
Squashing multiple commits to a single one overwrites the history which is why it
is recommended to be done using full caution. This step can be done by running
the command: git rebase -i HEAD~{{N}} where {{N}} represents the number
of commits needed to be squashed.

Can you tell the differences between git revert and git reset?

git revert git reset

This command is used for creating a new This command is used for undoing
commit that undoes the changes of the the local changes done in the git
previous commit. repository

Using this command adds a new history to This command operates on the
the project without modifying the existing commit history, git index, and the
history working directory.

What is the functionality of “git cherry-pick” command?

This command is used to introduce certain commits from one branch onto
another branch within the repository. The most common use case is when we
want to forward- or back-port commits from the maintenance branch to the
development branch.

How to revert a bad commit which is already pushed?

There can be cases where we want to revert from the pushed changes and go
back to the previous version. To handle this, there are two possible approaches
based on the situations:

 Approach 1: Fix the bad changes of the files and create a new commit
and push to the remote repository. This step is the simplest and most
recommended approach to fix bad changes. You can use the
command: git commit -m "<message>"
 Approach 2: New commit can be created that reverts changes done in
the bad commit. It can be done using git revert <name of bad commit>

1) What is GIT?

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 is a repository in GIT?

A repository contains a directory named .git, where git keeps all of its metadata
for the repository. The content of the .git directory are private to git.

3) What is the command you can use to write a commit message?

The command that is used to write a commit message is “git commit –a”. The –a
on the command line instructs git to commit the new content of all tracked files
that have been modified. You can use “git add<file>” before git commit –a if
new files need to be committed for the first time.

4) What is the difference between GIT and SVN?

The difference between GIT and SVN is

a) Git is less preferred for handling extremely large files or frequently changing
binary files while SVN can handle multiple projects stored in the same repository.

b) GIT does not support ‘commits’ across multiple branches or tags. Subversion
allows the creation of folders at any location in the repository layout.

c) Gits are unchangeable, while Subversion allows committers to treat a tag as a


branch and to create multiple revisions under a tag root.

5) What are the advantages of using GIT?

a) Data redundancy and replication

b) High availability

c) Only one.git directory per repository

d) Superior disk utilization and network performance

e) Collaboration friendly

f) Any sort of projects can use GIT

6) What language is used in GIT?

GIT is fast, and ‘C’ language makes this possible by reducing the overhead of
runtimes associated with higher languages.

7) What is the function of ‘GIT PUSH’ in GIT?

‘GIT PUSH’ updates remote refs along with associated objects.

8) Why GIT better than Subversion?

GIT is an open source version control system; it will allow you to run ‘versions’ of
a project, which show the changes that were made to the code overtime also it
allows you keep the backtrack if necessary and undo those changes. Multiple
developers can checkout, and upload changes and each change can then be
attributed to a specific developer.

9) What is “Staging Area” or “Index” in GIT?

Before completing the commits, it can be formatted and reviewed in an


intermediate area known as ‘Staging Area’ or ‘Index’.
10) What is GIT stash?

GIT stash takes the current state of the working directory and index and puts in
on the stack for later and gives you back a clean working directory. So in case if
you are in the middle of something and need to jump over to the other job, and
at the same time you don’t want to lose your current edits then you can use GIT
stash.

11) What is GIT stash drop?

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

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

Git branch—merged lists the branches that have been merged into the current
branch

Git branch—-no merged lists the branches that have not been merged

13) What is the function of git clone?

The git clone command creates a copy of an existing Git repository. To get the
copy of a central repository, ‘cloning’ is the most common way used by
programmers.

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

The ‘git config’ command is a convenient way to set configuration options for
your Git installation. Behaviour of a repository, user info, preferences etc. can be
defined through this command.

15) What does commit object contain?

a) A set of files, representing the state of a project at a given point of time

b) Reference to parent commit objects

c) An SHAI name, a 40 character string that uniquely identifies the commit


object.

16) How can you create a repository in Git?

In Git, to create a repository, create a directory for the project if it does not exist,
and then run command “git init”. By running this command .git directory will be
created in the project directory, the directory does not need to be empty.

17) What is ‘head’ in git and how many heads can be created in a
repository?
A ‘head’ is simply a reference to a commit object. In every repository, there is a
default head referred as “Master”. A repository can contain any number of
heads.

18) What is the purpose of branching in GIT?

The purpose of branching in GIT is that you can create your own branch and
jump between those branches. It will allow you to go to your previous work
keeping your recent work intact.

19) What is the common branching pattern in GIT?

The common way of creating branch in GIT is to maintain one as “Main“

branch and create another branch to implement new features. This pattern is
particularly useful when there are multiple developers working on a single
project.

20) How can you bring a new feature in the main branch?

To bring a new feature in the main branch, you can use a command “git merge”
or “git pull command”.

21) What is a ‘conflict’ in git?

A ‘conflict’ arises when the commit that has to be merged has some change in
one place, and the current commit also has a change at the same place. Git will
not be able to predict which change should take precedence.

22) How can conflict in git resolved?

To resolve the conflict in git, edit the files to fix the conflicting changes and then
add the resolved files by running “git add” after that to commit the repaired
merge, run “git commit”. Git remembers that you are in the middle of a
merger, so it sets the parents of the commit correctly.

23) To delete a branch what is the command that is used?

Once your development branch is merged into the main branch, you don’t need

development branch. To delete a branch use, the command “git branch –d


[head]”.

24) What is another option for merging in git?

“Rebasing” is an alternative to merging in git.

25) What is the syntax for “Rebasing” in Git?

The syntax used for rebase is “git rebase [new-commit] “

26) What is the difference between ‘git remote’ and ‘git clone’?
‘git remote add’ just creates an entry in your git config that specifies a name for
a particular URL. While, ‘git clone’ creates a new git repository by copying and
existing one located at the URI.

27) What is GIT version control?

With the help of GIT version control, you can track the history of a collection of
files and includes the functionality to revert the collection of files to another
version. Each version captures a snapshot of the file system at a certain point of
time. A collection of files and their complete history are stored in a repository.

28) 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

29) 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.

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

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

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

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

32) What is the difference between the ‘git diff ’and ‘git status’?
‘git diff’ is similar to ‘git status’, but it shows the differences between various
commits and also between the working directory and index.

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

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.

34) What is the function of ‘git rm’?

To remove the file from the staging area and also off your disk ‘git rm’ is used.

35) What is the function of ‘git stash apply’?

When you want to continue working where you have left your work, ‘git stash
apply’ command is used to bring back the saved changes onto the working
directory.

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

To find specific commits in your project history- by author, date, content or


history ‘git log’ is used.

37) What is ‘git add’ is used for?

‘git add’ adds file changes in your existing directory to your index.

38) What is the function of ‘git reset’?

The function of ‘Git Reset’ is to reset your index as well as the working directory
to the state of your last commit.

39) What is git Is-tree?

‘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.

40) How git instaweb is used?

‘Git Instaweb’ automatically directs a web browser and runs webserver with an
interface into your local repository.

41) What does ‘hooks’ consist of in git?

This directory consists of Shell scripts which are activated after running the
corresponding Git commands. For example, git will try to execute the post-
commit script after you run a commit.

42) Explain what is commit message?


Commit message is a feature of git which appears when you commit a change.
Git provides you a text editor where you can enter the modifications made in
commits.

43) How can you fix a broken commit?

To fix any broken commit, you will use the command “git commit—amend”. By
running this command, you can fix the broken commit message in the editor.

44) Why is it advisable to create an additional commit rather than


amending an existing commit?

There are couple of reason

a) The amend operation will destroy the state that was previously saved in a
commit. If it’s just the commit message being changed then that’s not an issue.
But if the contents are being amended then chances of eliminating something
important remains more.

b) Abusing “git commit- amend” can cause a small commit to grow and acquire
unrelated changes.

45) What is ‘bare repository’ in GIT?

To co-ordinate with the distributed development and developers team, especially


when you are working on a project from multiple computers ‘Bare Repository’ is
used. A bare repository comprises of a version history of your code.

You might also like