Table of content

Git Interview Questions

Git plays a vital role in many organizations to achieve DevOps and it is a must know technology. Ans hence this makes me prepare you for the most frequently asked Git interview questions.

Q1.What is the difference between Git and SVN?

1. Git is a Distributed version control system 1. SVN is a Centralized version control system
2. Git belongs to the 3rd generation of version control system 2. Svn belongs to the 2nd generation version control system
3. The client can clone entire repositories on their local system 3. Version history is stored on the server-side repository hence we cannot clone
4. We can do commit offline also 4. We can do only online commit
5. Push and pull operations are faster 5. Push and pull operations are slower
6. Works are shared automatically by commits 6. Nothing is shared automatically
7. Less preferred for extremely large files and frequently changes files 7. It can handle multiple projects stored in the same repository
8. It doe not support commits across multiple branches and tags 8. I allow the creation of folders at any location in the repository layout

Q2. What is Git?

Git is a version control system and source code management system, which is capable of managing both small projects and large projects with the same speed and efficiency.

Q3. What is the command used to write the commit message?

If I want to commit any new file, first I will add the file to the staging area by using the command git add <file name> and then commit by using git commit -a , where "-a" parameter tells Git to commit the content of all the tracked files that have been modified.

Q4.What is the repository in Git?

Git Repository is the one, which contains all the files with respect to the specific project application, and it also contains the directory called .git which stores all the metadata for that repository. The content of the .git directory is private to the repository.

Q5.What is the Bare Repository?

Bare Repository contains version control information and not working files. and it doesn't contain the special subdirectory .git, instead it contains contents of the .git subdirectory.

Q5.What are the Advantages of using Git?

  • Collaboration Free
  • High availability
  • Git branches are easy to create and merge.
  • Any sort of project can use Git
  • Only one .git directory per repository.

Q6.What is the function of Git Push in Git?

It updates the Remote references with associated objects.

Q7.Which language is used in Git?

Git uses C language because it reduces the Runtime.

Q7.What is the staging area in Git?

The staging area is also called as Index, where the staging area holds /keep all the files which are in the queue for next commit.

The files which are present in the staging area are not committed yet. we can move the files in and out from the staging area without affecting the git repository and its history of changes.

Q8.What is mean by stash in Git?

Stashing is nothing but temporary storage, where git stash command temporarily stores the modified files, untracked files and staged changes made to our working directory in its stack, and we can move forward and work on something else and can come back to the previous section and work whenever we want.

Q9.What is mean by 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.

Q10.What is Cloning in Git?

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

Q11.What is the Function of the git config?

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

Q12.what does commit object contains?

The commit object contains the following:

  • A set of files, representing the state of a project at a given point of time
  • Reference to parent commit objects
  • An SHAI name, a 40 character string that uniquely identifies the commit object.

Q13.How can you create a repository in Git?

In Git, to create a repository, First, we have to create a directory for the project if it does not exist, and then run the command git init. By running this command a hidden folder called .git folder will be created in the project directory, the important thing is that the directory should not be empty.

Q14.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 to as Master, which always points to the last commit. A repository can contain any number of heads.

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

Q16.What is the common branching pattern in Git?

The common way of creating a branch in GIT is to maintain one as the 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.

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

Q18.What is 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.

Q19.How Can we resolve the conflict in Git?

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.

Q20.Which Command did we use to delete a Branch in Git?

Once the feature branch has been merged with the main branch, the feature is no longer needed and hence we can delete that branch by using the command git branch -d <branch name>

Q21.Which is another option for merging in Git?

Rebasing is another option for merging in Gt.

Q22.What is the syntax for Rebasing in Git?

The syntax used for Rebase is git rebase<new commit>

Q23.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 an existing one located at the URL.

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

Q25.What is the Function of Git diff in Git?

Git diff shows the difference between the commits, commit and working directory.

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

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

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

Q29. What is the function of git rm?

To remove the file from the staging area the git rm command is used.

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

Q31.What is the use of git log?

git log is used to find the specific commit history in the project by Author, date, and content.

Q32.What is the use of git add command?

git add command is used to add file changes in the working directory to the index or staging area.

Q33.What is the function of git reset command?

The git reset command is used to reset the index as well working directory to the state of your last commit.

Q34.What is mean by git ls-tree?

git Is-tree used to represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.

Q35.Explain what is mean by 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.

Q36.How can you fix the broken commit?

We can fix the broken commit message by using the git commit --amend , by using this command we can fix the broken commit message in the editor.

Q37.Why is it advisable to create an additional commit rather than amending an existing commit?


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.

Q38.What is a 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 the version history of your code.

Q39. Name a few Git repository hosting services

Git Repository hosting services are as below:

  • Pikacode
  • Visual Studio Online
  • GitHub
  • Git Enterprise

Q40. What is Git fork? What is the difference between fork, branch, and clone?

Fork: Forking is nothing but creating a copy of a repository, it allows you to make changes or experiment with the changes without affecting the original project.

Difference between Fork, Branch, and Clone

Fork Branch Clone
The fork is a server-side copy of a repository, distinct from the original Branching is a new feature which is available in the modern version control system Cloning is the process of creating a local repository by using the command line
The fork allows you to make changes or experiment with the changes without affecting the original project The branch is used to store the history of commits. Cloning a repository means downloading a copy of source code from source control

Q41.What is the difference between a pull request and a branch?

The difference between the pull request and ranch are as follow:

Pull Request Branch
Pull operation involves updating the local version of a repository from a remote repository Branching is a new feature which is available in the modern version control system
when someone takes the repository, make their own branch, does some changes, then tries to merge that branch

A branch is just a separate version of the code

Q42.What is the difference between git pull and git fetch?

In the simplest terms, git pull does a git fetch followed by a git merge.

Git Pull Git Fetch
When you use to pull, Git tries to automatically do your work for you. It is context sensitive so Git will merge any pulled commits into the branch you are currently working in When you fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch.
pull automatically merges the commits without letting you review them first. If you don’t closely manage your branches, you may run into frequent conflicts. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use merge.

Q43.Explain the advantages of Forking Workflow

Advantages of Forking workflow are as follow:

  • The Forking Workflow is fundamentally different than other popular Git workflows. Instead of using a single server-side repository to act as the central codebase, it gives every developer their own server-side repository. The Forking Workflow is most often seen in public open source projects.
  • The main advantage of the Forking Workflow is that contributions can be integrated without the need for everybody to push to a single central repository that leads to clean project history. Developers push to their own server-side repositories, and only the project maintainer can push to the official repository.
  • When developers are ready to publish a local commit, they push the commit to their own public repository—not the official one. Then, they file a pull request with the main repository, which lets the project maintainer know that an update is ready to be integrated.

Q44.What is the difference between HEAD, working tree and index, in Git?

The difference between HEAD, working tree and Index are as follow:

Head Working Tree Index
HEAD is a reference to the last commit in the currently checked-out branch. The working tree/working directory/workspace is the directory tree of (source) files that you see and edit. The index/staging area is a single, large, binary file in <baseOfRepo>/.git/index, which lists all files in the current branch, their sha1 checksums, timestamps, and the file name - it is not another directory with a copy of files in it.
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions