Some Intermediate level Git Interview Questions and Answers, to help you to excel your interviews in 2023.

Intermediate git questions and answers

As promised earlier, we are providing some intermediate level Git Interview questions and answers in this blog post. We hope that they will help you in your technical interviews. Please go through and submit your feedback with us. We will also try to post some Advanced level Git Interview questions and answers in our upcoming blogs. We also have an e-book: Git Tutorials for Beginners: Mastering Version Control. You can go through this e-book and can clear your Git concepts. Meanwhile, if you want to get an idea about some of the beginner level Git interview questions and answers, please go through this blog post.

What is git history?

Git history represents a tree object including the mode and the name of each item and the sha1 value of the block of the tree.

What is git stash?

Often when you have been working on part of your project. If you want to switch branches for some time to do something else without committing the half-done work and you want to get back to this point later. To solve this issue there is one provision called “git stash”. Stashing takes your working directory that is your modified track files and stage changes and saves it on a stack of unfinished changes that you can reapply at any time.

What is the function of git stash apply?

After stashing your changes, if you want to continue working where you had left your work then “git stash apply” command is used to bring back these saved changes onto your current working directory.

What work is restored when the deleted branch is recovered?

The files which were stashed and saved in the stash index list will be recovered back. Any untracked files will be lost; therefore, it is a good idea to always stage and commit your work or stash them.

Explain the difference between git status and git diff.

Git diff depicts the changes between the commits and between the working tree etc. whereas Git status shows you the difference between the working directory and the index. Git status is helpful in understanding git a bit more comprehensively.
Git diff is similar to git status the only difference is that it shows the differences between the various commits and also between the working directory and the index.

Mention the differences between the git clone and git remote.

Git remote creates an entry into your git config that specifies a name for a particular URL whereas get clone creates a new git repository by copying an existing one located at the URL.

What is git stash drop?

Git stashes drop command is used to remove the stashed item. It will remove the last added stash item by default, and it can also remove a specific item.

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

To get a list of files that has changed in a particular commit, use the get diff-tree -r . This will list all the files that were changed or added in that commit. The -r flag makes the command, list individual files rather than collapsing them into the root directory names only.

What is the function of git config?

Git uses your username to associate commits with an identity. The “git config” command can be used to change your git configuration including your username. Suppose you want to give a username and an email ID to associate a commit with an identity so that you can know who has made a particular commit. For that there are two commands:
git config — global<username>
git config — global<your email address>

What does the commit object contain?

Commit object basically contains three components, first a set of files representing the state of a project at any given point of time. The second one is the reference to the parent commit objects and the third one is a sha1 name which is a 40-character string that uniquely identifies the commit object.

Describe the branching strategies that you have used.

This question is asked to test your branching experience with Git so here we are going to discuss the three branches.
Starting with the first one that is a Feature branching. A Feature Branch model keeps all of 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 the master.

The second is the task branching in this model each task is implemented on its own branch with the task key included in the branch name. It is easy to see which code implements which task by just looking at the task key in the branch name and

The third branching is the release branching. Once the develop branch has acquired enough features for a release, you can clone that branch to form a release branch. Creating this branch starts the next release cycle. No new features can be added after this point. Only bug fixes, documentation generation and other release-oriented tasks should go in this branch. Once it is ready to ship the release, gets merged into the master and tagged with a version number. In addition, it should be merged back into the develop branch which may have progressed since the release was initiated.

Explain the advantages of forking workflow.

There is a fundamental difference between the forking workflow and the other popular git workflows. Rather than using a single server site to act as a central code base, it gives every developer their own server-side repository. The forking workflow is commonly seen in public open-source projects.

A crucial advantage of forking workflow is that contributions can be generated even without needing everybody to push to a single central repository, that leads to the clean project history. Developers can push to their own server-side repositories. but only the project maintenance can push to the official repository.

If developers are ready to publish a local commit, then they push the commit to their own public repository and not the official one. So, after this they go for a pull request with the main repository, that lets the project maintainer know an update is ready to be integrated.

How will you know and get if a branch has already been merged into the master?

There are two commands to check this. The first command is the “git branch — merged”, this command lists the branches that have been merged into the current branch. The second one is the “git branch — no – merged”, this command lists the branches that have not been merged.

Why is it desirable to create an additional commit rather than amending an existing commit?

There are two reasons for this, the first one is the amend operation destroys the state that was previously saved in a commit. If there is just the commit message that is being changed then that is not a problem, but if the contents are being amended then the chances of eliminating something important remains more. The second reason is that abusing “git — amend” command can result in the growth of a small commit and acquire unrelated changes.

How to remove a file from get without removing it from your file system?

One has to be very careful during a get add else you may end up adding the files that you didn’t want want to commit. However “git rm” command will remove it from both your staging area as well as your file system but this may not be what you want. Instead you can use the command “git rm –cached ” for directory use the command “git rm –cached -r “. When –cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.

Could you explain the git workflow?

To record the history of the project, git workflow employs two parallel long running branches the first one is the master branch and the second one is the develop branch. The master branch is always ready to be released on live with everything fully tested and approved that is production ready state. The hotfix branch in master is used to quickly patch the production release.

These branches are a lot like the release branches and the feature branches except that they are based on master instead of the develop. The second branch is the develop branch, to which all the feature branches are merged and where all the tests are performed.

Only when everything’s been thoroughly checked and fixed it can be merged into the master. Here there’s one more branch called feature Branch so each new feature should reside in its own branch which can be pushed to develop branch as their parent one.

What is the difference between fork branch and clone?

A fork is a copy of a repository. Normally you Fork a repository so that you’re able to freely experiment with changes without affecting the original project. Most commonly forks are either used to propose changes to someone else’s project or to use someone else’s project as a starting point of your own idea.

Git cloning means pointing to an existing repository and make a copy of that repository in a new directory at some other location. The original repository can be located on the local file system or on the remote machine accessible by supported protocols. The git clone command is used to create a copy of an existing git repository in very simple word.

What are the different ways by which you can refer to a commit?

In git each commit has a unique hash, these hashes are used to identify the corresponding commits in various scenarios, for example while trying to check out a particular state of a code using the “git checkout ” command along with hash, git maintains a number of alliances to certain commits known as the refs.

Also, every tag that is created in this repository effectively becomes a ref and that is exactly why you can use tags instead of committing hashes in various get commands. Git also maintains a number of special analyses that are changed based on the state of the repository. In git commits are allowed to be referred to as relative to one another. In case of most commits where the commit has two parents the raised to (^) sign can be used to select one of the two parents. However, these can also be used to refer to commits that reside on remote branches allowing one to control and manipulate them from the local git environment.

What is the difference between rebasing and merging?

In git the rebase command is used to integrate changes from one branch into another, it is an alternative to the merge command. The difference between rebasing and merging is that, rebase rewrites the commit history in order to produce a straight linear succession of commits, merging is gets way of putting a forked history back together. Again, the git merge command helps you take the independent lines of development created by git branches and integrate them into a single branch.

Mention the difference between revert and reset.

Reset is used to return the entire working tree to the last committed state. This will scrub commits in a private branch or throw away uncommitted changes. Reset changes which commit a branch head is currently pointing at it, alters the existing commit history. This command can also be used to unstage a file whereas git revert command creates a new commit that undergoes the changes from a previous commit. This command adds new history to the project. It doesn’t modify the existing history.


In this blog post, we’ve gone through a range of intermediate-level Git interview questions and answers to help you prepare for more challenging discussions in your Git-related job interviews.

As you’ve seen, Git requiring a deeper understanding of version control principles and Git workflows. By studying these questions and answers, you’ve taken an important step toward becoming a more proficient Git user.

Git is a dynamic tool with an array of advanced features, and there’s always more to learn. We will also post some Advanced-level Git interview questions and answers in near future, so please go-through that also.
Don’t hesitate to explore Git’s extensive documentation, participate in collaborative coding projects, and experiment with different workflows to further enhance your expertise.

For your help we have compiled an e-book Git Tutorials for Beginners: Mastering Version Control. This will further help you in increasing your knowledge.

Should you have any questions or require clarification on any of the topics covered here, please feel free to reach out. We wish you the best of luck in your upcoming interviews, and may you impress your potential employers with your Git proficiency and overall professionalism.

Leave a Reply

Shopping cart


No products in the cart.

Continue Shopping