Top 75+ Git Interview Questions and Answers

Git is the most popular source code management tool. Whether you're a programmer or a non-technical person, Git will help you with its collaboration features like bug tracking, task management, and wikis. 

Git plays a significant role in an organization to implement DevOps methodologies. Looking at the popularity of Git in DevOps, it's quite evident that there will be many job opportunities in the near future. According to a report from Grand View Research, the global DevOps market is expected to reach 12.85 Bn by 2025, growing at a CAGR of 18.60%. Here are some of the top Git interview questions that will help you crack an interview.

Post Graduate Program in DevOps

Designed in collaboration with Caltech CTMEExplore Course
Post Graduate Program in DevOps

Basic Git Interview Questions

1. What is Git?

Git is a version control system for tracking changes in computer files and is used to help coordinate work among several people on a project while tracking progress over time. In other words, it’s a tool that facilitates source code management in software development.

Git favors both programmers and non-technical users by keeping track of their project files. It enables multiple users to work together and handles large projects efficiently.

git-1

2. What do you understand by the term ‘Version Control System’?

A version control system (VCS) records all the changes made to a file or set of data, so a specific version may be called later if needed.

This helps ensure that all team members are working on the latest version of the file

server

3. What is GitHub?

   To provide Internet hosting for version control and software development, GitHub makes use of Git. 

4. Mention some popular Git hosting services.

  • GitHub
  • SourceForge
  • GitLab
  • Bitbucket

5. Different types of version control systems

  • Local version control systems have a database that stores all file changes under revision control on disc in a special format.
  • Centralized version control systems have a single repository, from which each user receives their working copy.
  • Distributed version control systems contain multiple repositories, and different users can access each one with their working copy.

6. What benefits come with using GIT?

  • Data replication and redundancy are both possible.
  • It is a service with high availability.
  • There can only be one Git directory per repository.
  • Excellent network and disc performance are achieved.
  • On any project, collaboration is very simple.

7. What’s the difference between Git and GitHub?

Git

GitHub

Git is a software

GitHub is a service

Git can be installed locally on the system

GitHub is hosted on the web

Provides a desktop interface called git GUI

Provides a desktop interface called GitHub Desktop.

It does not support user management features

Provides built-in user management

FREE GIT Training

Learn the basics of GITEnroll Now
FREE GIT Training

8. What is a Git repository?

Git repository refers to a place where all the Git files are stored. These files can either be stored on the local repository or on the remote repository.

git-repo

9. How can you initialize a repository in Git?

If you want to initialize an empty repository to a directory in Git, you need to enter the git init command. After this command, a hidden .git folder will appear.

taha-git

10. How is Git different from Subversion (SVN)?

GIT

SVN

Git is a distributed decentralized version control system

SVN is a centralized version control system.

Git stores content in the form of metadata.

SVN stored data in the form of files.

The master contains the latest stable release.

In SVN, the trunk directory has the latest stable release 

The contents of Git are hashed using the SHA-1 hash algorithm.

SVN doesn’t support hashed contents. 

11. Name a few Git commands with their function.

  • Git config - Configure the username and email address
  • Git add - Add one or more files to the staging area
  • Git diff - View the changes made to the file
  • Git init - Initialize an empty Git repository
  • Git commit - Commit changes to head but not to the remote repository

12. What are the advantages of using Git?

  • Faster release cycles
  • Easy team collaboration
  • Widespread acceptance 
  • Maintains the integrity of source code
  • Pull requests

git-7.

13. What language is used in Git?

Git is a fast and reliable version control system, and the language that makes this possible is ‘C.’ 

Using C language reduces the overhead of run times, which are common in high-level languages.

DevOps Certification Training Course

Gain expertise in the top DevOps toolsExplore Course
DevOps Certification Training Course

14. What is the correct syntax to add a message to a commit?

 git commit -m "x files created"

15. Which command is used to create an empty Git repository?

git init - This command helps to create an empty repository while working on a project. 

16. What does git pull origin master do?

The git pull origin master fetches all the changes from the master branch onto the origin and integrates them into the local branch.

git pull = git fetch + git merge origin/ master

After having gone through the beginner level Git interview questions, let us now look at intermediate GIT interview questions and answers.

Intermediate Git Interview Questions

17.  What does the git push command do?

The Git push command is used to push the content in a local repository to a remote repository. After a local repository has been modified, a push is executed to share the modifications with remote team members.

Git-push-command

18. Difference between git fetch and git pull.

Git Fetch

Git Pull

The Git fetch command only downloads new data from a remote repository.

Git pull updates the current HEAD branch with the latest changes from the remote server.

It does not integrate any of these new data into your working files.

Downloads new data and integrate it with the current working files.

Command - git fetch origin

git fetch --all

Tries to merge remote changes with your local ones.

Command - git pull origin master

19. GitHub, GitLab and Bitbucket are examples of git repository _______ function?

hosting. All the three are services for hosting Git repositories

20. What do you understand about the Git merge conflict?

A Git merge conflict is an event that occurs when Git is unable to resolve the differences in code between the two commits automatically. 

Git is capable of automatically merging the changes only if the commits are on different lines or branches.

merge-conflict.

Free Course: Introduction to DevOps Tools

Master the Fundamentals of DevOps ToolsEnroll Now
Free Course: Introduction to DevOps Tools

21. How do you resolve conflicts in Git?

Here are the steps that will help you resolve conflicts in Git:

  • Identify the files responsible for the conflicts.
  • Implement the desired changes to the files 
  • Add the files using the git add command.
  • The last step is to commit the changes in the file with the help of the git commit command.

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

The git ls-tree command is used to list the contents of a tree object.

23. What is the process to revert a commit that has already been pushed and made public?

There are two processes through which you can revert a commit:

1. Remove or fix the bad file in a new commit and push it to the remote repository. Then commit it to the remote repository using:

git commit –m “commit message”

2. Create a new commit to undo all the changes that were made in the bad commit. Use the following command:

git revert <commit id>

24. How is a bare repository different from the standard way of initializing a Git repository?

Standard way

Bare way

You create a working directory with the git init command.

Does not contain any working or checked out copy of source files.

A .git subfolder is created with all the git-related change history.

Bare repositories store git revision history in the root folder of your repository instead of the .git subfolder.

25. What does git clone do?

Git clone allows you to create a local copy of the remote GitHub repository. Once you clone a repo, you can make edits locally in your system rather than directly in the source files of the remote repo

26. What is Git stash?

Let’s say you're a developer and you want to switch branches to work on something else. The issue is you don’t want to make commits in uncompleted work, so you just want to get back to this point later. The solution here is the Git stash. 

Git stash takes your modified tracked files and saves it on a stack of unfinished changes that you can reapply at any time. To go back to the work you can use the stash pop.

27. What does the git reset --mixed and git merge --abort commands do?

git reset --mixed is used to undo changes made in the working directory and staging area.

git merge --abort helps stop the merge process and return back to the state before the merging began.

28. What do you understand about the Staging area in Git?

The Staging Area in Git is when it starts to track and save the changes that occur in files. These saved changes reflect in the .git directory. Staging is an intermediate area that helps to format and review commits before their completion.

DevOps Engineer Master's Program

Bridge between software developers and operationsExplore Course
DevOps Engineer Master's Program

29. What is Git Bisect and how do you use it?

The Git Bisect command performs a binary search to detect the commit which introduced a bug or regression in the project’s history.

Syntax: git bisect <subcommand> <options>

30. How do you find a list of files that has been changed in a particular commit?

The command to get a list of files that has been changed in a particular commit is:

git diff-tree –r {commit hash}

  • -r flag allows the command to list individual files
  • commit hash lists all the files that were changed or added in the commit.

31. What is the use of the git config command?

The git config command is used to set git configuration values on a global or local level. It alters the configuration options in your git installation. It is generally used to set your Git email, editor, and any aliases you want to use with the git command.

32. What is the functionality of git clean command? 

The git clean command removes the untracked files from the working directory.

33. What is SubGit and why is it used?

SubGit is a tool that is used to migrate SVN to Git. It transforms the SVN repositories to Git and allows you to work on both systems concurrently. It auto-syncs the SVN with Git.

34. If you recover a deleted branch, what work is restored?

The files that were stashed and saved in the stashed index can be recovered. The files that were untracked will be lost. Hence, it's always a good idea to stage and commit your work or stash them. 

35. Explain these commands one by one– git status, git log, git diff, git revert <commit>,  git reset <file>.

  • Git status - It shows the current status of the working directory and the staging area.
  • Git revert<commit> -  It is used for undoing changes to a repository's commit history.
  • Git log- It is a key tool for reviewing and reading the history of everything that happens to a repository.
  • Git diff- It is a multi-purpose Git command that performs a diff function on Git data sources when executed.
  • Git reset<file>- it is used to unstage a file.

36. What exactly is tagging in Git?

Tagging enables developers to mark all significant checkpoints as their projects progress.

37. What exactly is forking in Git?

It is a repository duplicate and forking allows one to experiment with changes without being concerned about the original project. 

38. How to change any older commit messages?

You can change the most recent commit message with the git commit —amend command.

39. How to handle huge binary files in Git?

Git LFS is a Git extension for dealing with large and binary files in a separate Git repository.

40. Name a few GIT tools.

Git comes with a few built-in tools like Git Bash and Git GUI.

41. Will you make a new commit or amend an existing one?

The git commit —amend command allows you to easily modify the most recent commit.

42. What do you mean by branching strategy?

It is employed by a software development team while writing and managing code with a version control system.

43. Difference between head, working tree, and index.

They are all names for various branches. Even Though a single git repository can track an arbitrary number of branches, the working tree is only associated with one of them, and HEAD points to that branch.

44. Is there a git GUI client available for Linux?

Git includes built-in GUI tools for committing (git-gui) and browsing (gitk), but there are a number of third-party tools available for users seeking platform-specific experience.

45. What is the benefit of a version control system?

Version control enables software teams to maintain efficiency and agility while the team grows by adding more developers

DevOps Engineer Exam Practice Test

Assess your understanding of the DevOps conceptsTry answering
DevOps Engineer Exam Practice Test

46. What do you mean by git instaweb?

 It is a script used to set up a temporary instance of Gitweb.

47. What exactly is the forking workflow?

Forking is a git clone operation that is performed on a server copy of a project's repository.

48. Mention benefits of forking workflow.

Contributions can be integrated without everyone trying to push to a single central repository.

49. What is the Gitflow workflow?

The Gitflow Workflow specifies a strict branching model centered on the project release.

50. What does the commit object contain?

The commit object contains a tree of blob objects and other tree objects that represent the project revision's directory structure.

51. Write the syntax of rebasing in git.

Syntax is as follows: $git rebase <branch name>

52. What are Git Hooks?

They are scripts that are executed automatically whenever a specific event occurs in a Git repository.

53. What is Git stash vs Git stash pop?

Git stash pop removes the (topmost, by default) stash when applied, whereas git stash apply keeps it in the stash list for future use.

54. Explain git reflog This command is used by Git to record changes made to the branches' tips.

55. Role of the git annotate command.

In git, it is used to track each line of the file based on the commit information.

56. What is a git Directory?

It is the storage place of the metadata and object database of the project.

57. How can a conflict be settled in Git?

Edit the files to resolve any incompatible changes first, then use "git add" to add the corrected files and "git commit" to save the repaired merge.

58. What is the standard method for branching in GIT?

In GIT, the best way to create a branch is to have one'main' branch and then another branch for implementing the changes that we want to make.

FREE DevOps Certification Training

Master the fundamentals of DevOpsStart Learning
FREE DevOps Certification Training

59. How do you set up a Git repository?

If you want to add an empty repository to a directory in Git, use the git init command.

60. What is the proper syntax for appending a message to a commit?

Git commit -m "x files created" is the syntax.

61. Use of git instaweb.

It is used to launch a web browser and a webserver with an interface into a local repository automatically.

62. Describe git is-tree.

It represents a tree object with each item's mode and name included.

63. What exactly is git cherry-pick?

A command typically used to move specific commits from one branch of a repository to another.

64. State the difference between “git remote” and “got clone”?

“Git remote” allows you to create an entry in the git configuration which specify a URL.

“Git clone” lets you create a new git repository by letting you copy it from the  current URL.

65. Difference between “pull request” and “branch”?

“Pull request” is done when you feel like changing the developer’s change to another person's code branch. And “Branch” is just a separate version of code. 

66. How might you recover a branch that has previously pushed changes in the main repository yet has been coincidentally erased from each team member's local machines?

We can easily recover this by seeing the latest commit of the branch in the reflog and then going through the new branch. 

67. What is a detached head? 

Detach head refers to that the currently checked repository is not in the local branch. 

68. What command helps us to know the branches merged into master and which are not?

git branch  - -merged lets us get the lost of the branches which are currently merged into the current branch  

git branch - - no- merged shows the branches which are not merged 

69. Is LDAP Authentication Supported? 

GitLab API only supports LDAP authentication since version 6.0 and higher. 

Now let’s raise the level of difficulty with advanced Git interview questions and answers.

Interested to learn more about Git? Check out the DevOps Engineer Master's Program and get certified today.

Advanced Git Interview Questions

70. Explain the different points when a merge can enter a conflicted stage.

There are two stages when a merge can enter a conflicted stage.

1. Starting the merge process

If there are changes in the working directory of the stage area in the current project, the merge will fail to start. In this case, conflicts happen due to pending changes that need to be stabilized using different Git commands.

2. During the merge process

The failure during the merge process indicates that there’s a conflict between the local branch and the branch being merged. In this case, Git resolves as much as possible, but some things have to be fixed manually in the conflicted files.

71. What has to be run to squash the last N commits into a single commit?

In Git, squashing commits means combining two or more commits into one.

Use the below command to write a new commit message from the beginning.

git reset -soft HEAD~N &&git commit

But, if you want to edit a new commit message and add the existing commit messages, then you must extract the messages and pass them to Git commit.

The below command will help you achieve this: 

git reset -soft HEAD~N &&git commit -edit -m“$(git log -format=%B -reverse .HEAD@{N})”

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

Fork

Branch

Clone

The fork is the process when a copy of the repository is made. It's usually experimentation in the project without affecting the original project. They’re used to advise changes or take inspiration from someone else’s project.

Git branches refer to individual projects within a git repository. If there are several branches in a repository, then each branch can have entirely different files and folders.

Git clone refers to creating a clone or a copy of an existing git repository in a new directory. Cloning automatically creates a connection that points back to the original repository, which makes it very easy to interact with the central repository.

73. How is Git merge different from Git rebase?

Git merge is used to incorporate new commits into your feature branch.

feature-master

  • Git merge creates an extra merge commit every time you need to incorporate changes.
  • It pollutes your feature branch history.

As an alternative to merging, you can rebase the feature branch into master.

feature-master2

  • Git rebase Incorporates all the new commits in the master branch.
  • It rewrites the project history by creating brand new commits for each commit in the original branch

74. What is the command used to fix a broken commit?

To fix a broken commit in Git, you may use the “git commit --amend” command, which helps you combine the staged changes with the previous commits instead of creating an entirely new commit.

75. How do you recover a deleted branch that was not merged?

To recover a deleted branch, first, you can use the git reflog command. It will list the local recorded logs for all the references. Then, you can identify the history stamp and recover it using the git checkout command.

FREE DevOps Certification Training

Master in-demand DevOps tools and skillsEnroll for FREE
FREE DevOps Certification Training

76. What is git stash drop?

The Git stash drop command is used to remove a particular stash. If there’s a stash you're no longer using or you want to remove a specific item of stash from the list, you can use the stash commands.

Let’s say you want to delete an item named stash@{abc}; you can use the command:

git stash drop stash@{abc}.

77. What’s the difference between reverting and resetting?

Reverting

Resetting

The revert command in Git is used to create a new commit that undoes the changes made in the previous commit. When you use this command, a new history is added to the project; the existing history is not modified.

Git reset is a command that is used to undo the local changes that have been made to a Git repository. Git reset operates on the following: commit history, the staging index, and the working directory.

78. How can you discover if a branch has already been merged or not?

There are two commands to determine these two different things.

git branch --merged - Returns the list of branches that have been merged into the current branch.

git branch --no-merged - Returns the list of branches that have not been merged.

79. What is “git cherry-pick”?

The command git cherry-pick enables you to pick up commits from a branch within a repository and apply it to another branch. This command is useful to undo changes when any commit is accidentally made to the wrong branch. Then, you can switch to the correct branch and use this command to cherry-pick the commit.

Transform your DevOps career and learn the science of improving the operational and developmental activities by choosing our PGP in DevOps. Contact our admission counselor today and grab your seat!

Become a DevOps Expert!

By now you should have an idea of the Git interview questions that could be asked and what possible answers should be given. However, if you wish to bag the job like a pro, you can enroll in Simplilearn's DevOps Certification Training Course that teaches you about the tools and techniques you need to bridge the gap between software developers and operations. You’ll become an expert in the principles of continuous development and deployment, automation of configuration management, inter-team collaboration, and IT service agility, using modern DevOps tools such as Git, Docker, Jenkins, Puppet, and Nagios. 

About the Author

Sana AfreenSana Afreen

Sana Afreen is a Senior Research Analyst at Simplilearn and works on several latest technologies. She holds a degree in B. Tech Computer Science. She has also achieved certification in Advanced SEO. Sana likes to explore new places for their cultures, traditions, and cuisines.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.