60+ Best GIT Interview Questions To Hire Or Get Hired With

Both Git and GitHub continue to be indispensable tools for large technology organizations in the modern era. Git allows multiple engineers to cooperatively work on a single product; each individual engineer can work on a particular part of the code without interfering with the work of the other engineers on the team. At the end of the process, members of the team can seamlessly merge their work together using the Git repository. In simplest terms, the Git repository is a version management system which allows multiple versions of a piece of code to exist simultaneously. This means one engineer safely build on top of existing versions of the code before merging it into the master branch once the functionality of the revision is confirmed. This final version can then be easily deployed to users.

Experienced engineers know that Git and GitHub have become an essential aspect of the job. Many professionals in the field are likely to use Git and GitHub hundreds of times each week. Because of this, an interviewee’s knowledge of these important programs could make or break the job application process.Below are some helpful git interview questions and answers to get help to prepare readers for their next big job interview. If you are looking for GitHub interview questions, these questions should be a great place to start.


Before we begin

Here is a short video explaining what Git is. I find it helpful to watch this so that you can get an understanding of how to talk about Git to those who might not know much about the particular space.


1. What is Git?

• Git is a distributed version control system and source code management (SCM) system acclaimed by developers its ability to handle both small and large projects with impressive speed and efficiency.
• Git is very effective at tracking changes to a file, which allows developers to easily revert back to any particular version of their product during the development process.
• Its distributed architecture gives Git significant advantages over other version control systems. One great aspect of this system is that it does not rely on a central server to store all the versions of project files, but instead distributes them across multiple servers.
• The software allows developers to clone a copy of the repository and access the full history of the project on the hard drive. In the case of a server outage, server outage the local Git repository can then be used for painless recovery.
• Additionally, the software has a central cloud repository that allows developers to commit changes and share them with other teammates while other collaborators make revisions to the remote repository.

2. Explain what a Git repository is.

• This is a directory named .Git which contains all metadata for the repository.
• The content of the .Git directory is private to Git.

3. Describe what a bare repository in Git is.

• A bare repository is a directory that does not contain the special .Git subdirectory, but instead stores the version control information and n working files.
• The directory contains all contents of the Git subdirectory within the main directory itself.
• The working directory consists of a working tree, as well as the checked-out copies of existing project files.
• The .Git subdirectory is where the Git-related version history of the repo is stored.

4. Explain the main ways you could refer to a commit.

• In the Git system, every single commit is given its own unique hash. Typically, these hashes are used to identify corresponding commits in various scenarios. For example, these hashes might be useful while trying to checkout a particular state of the code using the checkout {hash} command.
• Git is able to apply a number of different aliases to a specific commit. Additionally, every tag created in the repository functionally becomes a ref, which allows developers to use tags instead of commit hashes when structuring various Git commands. Git can also effectively maintain many special aliases which can change depending on the state of the repository, such as Head, Fetch_Head, and Merge_head.
• Git also makes it possible for commits to be referred to based on their relation to one another. For instance, HEAD~1 refers to the commit parent to HEAD, while HEAD~2 refers to the grandparent of HEAD. In merge commits where the commit has two separate parents, ^ is used to select one of the two parents. If HEAD had two parents, HEAD^2 would be the command used to follow the second parent.
• Another way to merge commits is through the use of refspecs. These are used to map local and remote branches together. However, they can also potentially be used to refer to commits that are located in remote branches, allowing someone to control and manipulate them from a local Git environment.

5. Give the command you would use to write a commit message.

I would use “Git command -a” to write a commit message.

In this command, -a instructs Git to commit the new content of all tracked files that have just been modified.

Developers can also add “Git add file” before Git commit -a if the referenced files are being committed for the first time.

6. Explain the difference between Git and SVN.

• Git is a decentralized version control tool, and SVN is centralized. This means that while the latter stores its files on a single central network Git is distributed across multiple.
• Git also belongs to the third generation of version control tools, while SVN is a second generation tool.
• In Git, software clients can clone entire repositories on their local systems. SVN, on the other hand, stores the versions history on the server-side repository.
• Git commits are possible even when offline, while SVN only allows online commits.
• Git developers benefit from faster push/pull operations than those available on the notably slower SVN..
• Git works are also shared automatically via commit. Under the SVN system, nothing is shared automatically.

7. Explain the major benefits developers get when using Git

• Data redundancy and replication
• High availability
• Only one .Git directory per repository
• Superior disk utilization and network performance
• Collaboration friendly
• Any sort of projects can use Git

8. What language is used in Git?

• Git utilized the ‘C’ language, which makes software faster and significantly reduces the overhead of runtimes associated with some of the higher languages

9. Describe the function of “Git Push” in Git.

The function ‘Git PUSH’ updates remotes refs along with associated objects

10. Explain why Git is better than Subversion.

Typically, Git is an open source version control system; it allows developers to run versions of a project while displaying the changes made to the code over time. The open source nature of Git also allows the developer to keep the backtrack if necessary, undoing unwanted changes.

When there are multiples developers, it is possible to checkout and upload changes while still attributing each change to a specific developer working on the project.

11. Explain what a “staging area” or Index is.

• Before the commits are completed, developers can format and review them in an intermediate area. This area is commonly referred to as the “staging area” or “index”

12. Define Git stash.

• This a tool used to record the current state of the working directory and index, place the information on the stack for later reference, and allow developers access to a clean working directory.
• When a developer is working on something and needs to move to another job but also does not want to lose the current edit, they can call Git stash for this operation.

13. Define Git stash drop.

The Stash Drop command is used when the developer wants to remove a stashed item form the list. This function removes the stashed item by default, but it can also remove a specific item if it is used as an argument.

14. What is a conflict in Git and how it can be resolved?

Conflict in Git occurs when more than one commit needs to be merged but the commits have differing changes in the same place or line of code. Git will have trouble predicting which change should take precedence, creating what is referred to as a Git conflict. The conflict can be resolved by first editing the files to fix the conflicting changes and then adding the resolved files by running Git add. Additionally, the developer must run Git commit to commit the repaired merge.The Git software will remember that the developer is merging and will then set the parents of the commit correctly.

15. Explain the contents of a commit object.

The commit object contains:

• A set of files indicating 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

16. Define a sub Git.

This is a tool for SVN to Git migration. It creates a writable Git mirror of a local or remote subversion repository and uses both subversion and Git at the discretion of the developer.

17. Explain what a HEAD is.

• The HEAD is a reference to the present looked-at conferring.
• It is a representative reference to the branch that we have looked at.
• At any given time, one head is chosen as the “present head.” This head is also referred as HEAD.

18. Explain the major Git design objectives.

• Distributed workflow (decentralized)
• Easy merging (merge deemed more frequent than commit)
• Integrity (protection against accidental or malicious corruptions)
• Speed and scalability

19. Describe how you would know if a Git branch has already been merged into master.

• The Git branch merged list details the branches that have been merged into the current branch • Git branch no merged list shows the branches that have not been merged

20. Explain the use of Git Clone.

The command creates a copy of the existing Git repository.

Developers use the cloning process to obtain a copy of the central repository.

21. Explain the function of ‘Git config.’

This is used to set up configuration options for Git installation. Behavior of a repository, user information and preferences can all be defined using the ‘Git config’ command.

22. Describe Version control in Git.

Versions control automatically notifies the programmers whenever there is a conflict between the work of two people on the product. It is also used to maintain records of the changes on the project over time and proactively help to answer questions that users might have.

Version control allows programmers to keep a record of commits. Using this function, it is possible to go back in time and determine who wrote changes on a specific day, or even to identify the particular version that was used to generate a particular set of results. It is therefore used as a de facto undo feature in the editor, because all previous versions are already saved.

Git is relatively complex, but it is also widely used among developers both because of its ease of setup and because of a hosting site called GitHub.

23. Explain the benefits of using Git

• Flexible workflow; the software allows programmers to create their own distinct work process. They can utilize specific procedures that suit their projects. For instance, a programmer can use brought together or ace slave among other work processes.
• Git is relatively quick compared to many other control frameworks.
• Data integrity is possible with Git since Git utilizes SHA1. Information stored in the Git system is relatively less ending to degenerate.
• It is relatively easy to utilize. Beginners frequently use it to utilize their underlying activities. It also works with substantial size tasks.
• For ventures that require collaboration, Git is a clear no-brainer. There hundreds of prevalent open source programming projects over the globe utilizing Git.

24. Explain how you would create a repository in Git.

This can be done by first creating a directory for the project (if one does not already exist), and then running the command “Git Init”. .Git directory will be created in the project directory; the directory does not have to be empty.

25. Explain the purpose of branching in Git

• Branching allows programmers to create their own branch and then jump between the different branches.
• Additionally, it allows programmers to move to previous work while preserving changes in the current work.

26. Give the most popular branching pattern in Git.

• The typical branching pattern is formatted by maintaining one branch as the Main branch and creating another branch to implement new features.
• This pattern is most often used when there are multiple developers working on a single project

27. Explain the process of integrating a new feature in the main branch.

Developers can bring a new feature into the main branch by entering the command “Git merge” or “Git pull command.”

28. Give the command for deleting a branch in Git.

When the development branch is merged into the main branch, the developer will no longer need the development branch. The branch can then be deleted using “Git branch – d[head]”

29. Explain the functions you would use to remove a particular item from the list of stashed items.

Git stash list will display the list of stashed items. It will look something like this:

stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert “added file_size”
stash@{2}: WIP on master: 21d80a5 added number to log

If you want to remove an item named stash@{0}, for example, you would use the command Git stash drop stash@{0}.

30. What is the alternative method of merging in Git?

Rebasing is the alternative method for merging in the Git system.

31. Explain the difference between “Git remote” and “Git clone.”

The command “Git remote add” is used to create an entry into the Git config that specifies the name of a specific URL. On the other hand, the ‘Git clone’ command creates a new Git repository by copying an existing and previously located URI.

32. List the best graphical Git clients for Linux.

• Git Cola
• Git-g
• Smart Git
• Giggle
• Git GUI
• qGit

33. What are the advantages of using SubGit in Git?

• SubGit is generally considered to be a more effective tool for the migration process than Git-svn.
• It does not require users to revise the infrastructure that is already in place.
• It enables programmers to use all Git and all subversion features
• Provides genuine stress-free migration experience

34. Explain the use of ‘Git diff’ command in Git

The command Git diff is used to show changes between commits, commit, and working tree.

35. Explain the use of ‘Git status’ in Git.

This function will show the difference between the working directory and the index, which is helpful to generate a more comprehensive understanding of a particular git.

36. What is the function of ‘Git checkout’ in Git?

This command is used to update directories or specific files within the working tree and from other branches without merging them into a singular united branch.

37. Explain the use of ‘Git Rm’ command.

This command is used to remove file from both the staging area and the disk.

38. Explain the use of command ‘Git stash apply.’

This command allows a programmer to easily continue working where they left off. ‘Git stash apply’ brings back the saved changes onto the current the working directory.

39. Explain the use of the function ‘Git log’

This function is used to find specific commits in the project’s evolution, sorted by author, date, content, or history.

40. Explain how you can revert a commit that has been pushed and made public.

This is the most popular way for resolving this error would be to remove or resolve the base file via a new commit, pushing it to the remote repository. After the file has been effectively changed, the programmer can quickly to commit it to the remote repository.

The command used to do this would be Git commit -m “commit message”.

Another potential method to solve this problem is to create a new commit that undoes all of the changes made in the bad commit. The command used for this procedure is Git revert

41. Explain the difference between Git pull and Git fetch.

The function Git pull is used to pull new changes or commits form a particular branch for the central repository and update the target branch within the local repository.

On the other hand, the Git fetch function is a command used for the same purpose, although it works in a slightly different way. the function pulls all the new commits from the desired branch and stores them in a new branch located within the local repository. Developers looking to highlight the changes in the target branch should follow the Git fetch function must be followed by a Git merge. The target branch will only be effectively updated after the target branch is merged with the fetched branch. The function Git pull = Git fetch + Git merge helps to illustrate

42. Explain the ‘Git reset’ command or function.

This function is used resets the index and the working directory to the state of the last commit.

43. Describe what a Git Is-Tree function is.

The Git is-Tree indicates a tree object and includes the mode, the name of each item, and the SHA-1 value of the blob or the tree.

44. How would you use the Git Instaweb?

The Git instaweb automatically directs a web browser and runs webserver with an interface into the local repository.

45. What are hooks in Git?

These are shell scripts in the directory that are activated after running the corresponding Git commands. For example, the Git can attempt to execute the post commit script after the programmer runs a commit.

46. Describe what a commit message is.

• Commit messages are displayed following a commit change.
• The Git software provides a text editor which the developer can use to enter the modifications made in commits.

47. Describe how you could fix a broken commit.

The syntax used for fixing a broken commit is “Git commit – amend.” This command will fix the broken commit in the editor.

48. Explain why it is necessary to create an additional commit rather than amending an existing commit.

• The amend operation is known to destroy the state that was previously saved in a commit. If the contents are amended, then the developer runs the risk of eliminating important items.
• Amending could result in an abuse of “Git commit- amend” this might result in an initially small commit growing and acquiring unrelated changes.

49. List some popular Git repository hosting services.

• Pikacode
• Visual Studio Online
• GitHub
• GitEnterprise
• SourceForge.net

50. Give the syntax for rebasing in Git.

The syntax used for rebasing is “Git rebase [new-commit].”

51. Explain the functions you would use to find a list to of files that have changed in a particular commit

The first command is Git diff-tree -r {hash}.

This command will list all of the files that were changed or added in the commit. The -r flag formats the command list as individual files, rather than collapsing them into root directory.

The alternative command is Git diff-tree –no-commit-id –name-only -r {hash}.

52. Explain how you would squash the last N commits into a single commit.

The programmer can decide to write the new commit message from scratch by using this command:
Git reset –soft HEAD~N &&
Git commit

It is also possible for a developer to first edit the new commit messages with a concatenation of the existing commit messages. This can be done by extracting the messages and then passing them to Git commit.
The following syntax is used:
Git reset –soft HEAD~N &&
Git commit –edit -m”$(Git log –format=%B –reverse .HEAD@{N})”

53. Define the Git Bisect

• Git bisect is used to find the commit that introduced a bug by using binary search
• You can use the following command for bisecting is Git bisect <subcommand> <options></options>

54. Describe how you could determine the source of a regression using binary search.

The command uses binary search algorithms to find the commit in the project’s history that was introduced to a bug. The programmer will first need to contain the bug by identifying the bad commit and then identifying a good commit which came before the bug was introduced. The Git bisect command picks a commit between the two endpoints and asks whether a selected commit is good or bad. It then continues narrowing down the range until the exact commit that was introduced to the bug is identified and then changed.

55. What is a sanity check in Git?

The sanity check, sometimes referred to as a smoke test, determines whether it is possible and reasonable to continue testing.

56. How can you configure a Git repository to run a sanity check before making commits, and preventing them if they fail the test?

This can be done using the simple script related to the pre-commit hook of the repository. The pre-commit hook is activated before a commit is made, right before the commit message is entered.

The script allows a programmer to run other tools, including linters, while also running sanity checks on the changes being committed into the repository.

An example of the syntax used for the process is shown below:

#!/bin/sh
files=$(Git diff –cached –name-only –diff-filter=ACM | grep ‘.go$’)
if [ -z files ]; then
exit 0
fi
unfmtd=$(gofmt -l $files)
if [ -z unfmtd ]; then
exit 0
fi
echo “Some .go files are not fmt’d”
exit 1

57. Describe a few branching strategies you are familiar with.

• Feature ranching keeps all the changes for a particular feature inside of a branch When the feature is fully tested and validated by automated tests, the branch is then merged into master.
• Task branching implements on a single branch with the task key included in the branch name. It is easy to see the particular code that implements a task. The programmer would do it by checking for the tasks key in the branch name

Releasing branch: Upon acquiring enough features, the develop branch can be cloned to form a release branch. This allows the developer to proceed with the next release cycle. When it is ready to ship, the release will merge with master and tag it with a version number. It should be merged with a developing branch that progressed after the release was started.

58. Explain the difference between a Pull request and a branch in Git.

A branch is just a separate version of the code.

A pull request is when someone takes the repository, makes their own branch, makes some changes, and then attempts to merge that branch again into the other person’s code repository.

59. Define “Git cherry-pick’ function in Git application.

• The command Git cherry-pick is typically used to introduce commits from one branch within a repository to a different branch. A common use is to forward port or backport commits from a maintenance branch to a development branch.
• This is different than other methods such as the merge and rebase, which normally apply many commits onto another branch.
Syntax:
Git cherry-pick

60. What is the Git forking workflow?

This is a unique workflow in Git that uses a single server-side repository to act as the ‘central’ code base. The workflow provides a developer with a unique server-side repository. The forking workflow is most often used in public open-source projects

61. Describe the main advantages of using forking workflow.

Developers benefit from the forking workflow because contributions can be implemented without the need for all users to push to a single central repository that feeds into a clean project history. Typically, the forking workflow allows developers to push to their own server-side repositories, while only the project maintainer can push to the official repository.

When developers are ready to publish a local commit, they can push the commit to their own public repository—not the official one. They may then file a pull request with the main repository, which lets the project maintainer know that an update is ready to be integrated.

62. Describe the Gitflow workflow.

Gitflow workflow employs two parallel long-running branches to record the history of the project: master and develop:

Master branch is always ready to be released on LIVE, with everything fully tested and approved (production-ready).

Hotfix branches, sometimes called maintenance branches, are used to quickly patch production releases. Hotfix branches are a lot like release branches, but they are based on master instead of a developing branch.

Develop is the branch to which all feature branches are merged and where all tests are performed. Only when everything has been thoroughly checked and problems have been corrected will it be merged to the master.

Feature branches house each feature, which should reside in its own branch before being pushed to the develop branch as their parent.

63. Describe how you can remove a file from Git without removing it from your file system.

The function Git rm will remove a file from both the staging area (index) and the filesystem (working tree), although the staging area removal might be problematic on some project.

The best alternative here is:
Git reset filename # or
echo filename >> .Gitingore # add it to .Gitignore to avoid re-adding it
This means that Git reset <paths> is the opposite of Git add <paths>.

64. When do you use "Git rebase" instead of "Git merge"?

Both of these commands are designed to integrate changes from one branch into another branch - they just do it in very different ways.

Consider before merge/rebase:

A <- B <- C [master]
^
\
D <- E [branch]
after Git merge master:
A <- B <- C
^ ^
\ \
D <- E <- F
after Git rebase master:
A <- B <- C <- D <- E
With rebase developers use another branch as the new base for their work.
When to use:
If there is any doubt, the default should be to merge.
The choice for rebase or merge is based on what the developer wants their history to look like.

65. Describe the difference between the working tree and index in Git.

• The working tree/working directory/workspace is the directory tree of (source) files that developers can 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.
• HEAD is a reference to the last commit in the currently checked-out branch.

author: patrick algrim
About the author

Patrick Algrim is an experienced executive who has spent a number of years in Silicon Valley hiring and coaching some of the world’s most valuable technology teams. Patrick has been a source for Human Resources and career related insights for Forbes, Glassdoor, Entrepreneur, Recruiter.com, SparkHire, and many more.

Share

Help us by spreading the word