It is probably safe to assume that Git has become an essential part of any company that aims to maintain the DevOps philosophy. Even if you’re not concerned with software engineering, Git is probably the most useful tool when it comes to project management - it is a key component to successful teamwork and goal achievement. Most of the project-based companies require that their employees would know how to use the various tools that Git provides. In this tutorial, you will find the most commonly asked Git interview questions - they will help you secure a job position in a company that recognizes Git for the awesome tool that it is!
We’ll talk about the basic information, and after we’re both on the same page, move on to the more experienced versions of the same questions. Even though Git is an amazing tool, it has a pretty steep learning curve, so put on your thinking shoes and let’s begin!
Table of Contents
- 1. Why Basic Interview Questions are Important
- 1.1. Question 1: What is Git?
- 1.2. Question 2: What’s the difference between a ‘bare repository’ and a ‘working directory’?
- 1.3. Question 3: What’s the difference between a ‘fork’ and a ‘branch’?
- 1.4. Question 4: You’ve created a commit and pushed it, it is now public. However, you’ve noticed that there are still things that need to be changed. Can you do so in this stage of the commit? And if yes, how?
- 1.5. Question 5: What is ‘cherry-picking’?
- 1.6. Question 6: What is a ‘stash’?
- 1.7. Question 7: What is a Git 'stash drop'?
- 1.8. Question 8: How do you resolve ‘conflicts’ in Git?
- 1.9. Question 9: What’s the language used in Git?
- 1.10. Question 10: What’s a ‘pull request’?
- 1.11. Question 11: What is the most efficient way to find a bad commit?
- 1.12. Question 12: Do you know what is the difference between Git and GitHub?
- 1.13. Question 13: Can you name other Git repository hosting services?
- 1.14. Question 14: Do you know what does ‘commit object’ contain?
- 1.15. Question 15: Do you see any advantages of using Git?
- 2. Advanced Git Queries
- 2.1. Question 1: What is a ‘head’?
- 2.2. Question 2: What is ‘Git CONFIG’ used for?
- 2.3. Question 3: Can broken commits be fixed?
- 2.4. Question 4: What’s the difference between ‘get’ and ‘pull’?
- 3. Conclusions
Why Basic Interview Questions are Important
To start things off on the right track, we’ll begin with covering some of the basic, common Git commands and interview questions. A lot of the people tend to neglect and rush over the basics when preparing for their job interviews - this shouldn’t be the case! I guess this is obvious when you’re just starting to learn about Git and how to use it. However, even if you’re already an experienced Git user, you shouldn’t make the mistake of ignoring the basic information. Why so?
Latest Udacity Coupon Found:
UP TO 85% OFF
Limited-time Udacity Coupon
For a limited time only, get 70% off bundle subscriptions & extra 15% off upfront payments. Use this Udacity coupon & save big on high-quality learning!
You see, when people study Git interview questions, they usually don’t think about the moment of the interview itself. Sure, you might imagine the situation and the questions that you’ll be asked, but one thing that many fail to recognize is that (more often than not) there’s going to be a lot of stress involved. Stress leads to panic, which in turn might result in you forgetting even the most basic of information about Git - especially if you didn’t practice it ahead of time.
So, now that we’ve established why basic interview questions on Git are important, let’s move on to the actual questions themselves.
Question 1: What is Git?
Let’s face it - you probably saw this one coming.
It is difficult to imagine that your potential employers might ask you something else as one of the first Git interview questions. With this question, you’ll be able to create a general impression of your knowledge level, and your interviewers will know what to expect from the rest of the job interview.
So, what is Git?
Git is a piece of technology designed to track and log changes and alterations in any type of computer files, especially when it comes to those files which are used by more than one or two people (i.e. a company). In other words, companies use Git to manage their workflow and track their progress with various projects. The technology is mainly used in software engineering, but a lot of companies around the world - which have nothing to do with software what-so-ever - have adapted Git into their workflow. It is especially popular (and important too) developers and programmers - it is one of the most essential tools for companies who strive to achieve and maintain the DevOps philosophy.
Question 2: What’s the difference between a ‘bare repository’ and a ‘working directory’?
A very popular template for Git interview questions, comparisons are something that you’re more than likely to encounter in your job interview. The best way to go about them is to keep your answers short and to-the-point, but at the same time try to show that you have a thorough understanding of what you’re talking about.
A bare repository, as the name implies, does not contain any working files that are used in Git. There are no sub-directories, no version control - just a bare template. On the other hand, a working directory contains all of the above - working files (and their altering history), sub-directories, etc. You could say that the two areas are opposite of each other.
Question 3: What’s the difference between a ‘fork’ and a ‘branch’?
One of the very common Git interview questions, your potential employers might ask you to compare the two concepts, or to perhaps even just describe one of them.
The concept of a “fork” isn’t unique or exclusive to Git. You may find forks in a lot of areas that you look for. A good example of this would be cryptocurrency forks - major changes in the way that particular cryptocurrencies work. In Git, however, forks are much less controversial, with the technology being used in stable, “indoor” scenarios.
In Git, a fork is a copy of a repository that is completely separate from the original. A branch, however, is something that is used to change certain parts of a program (from the development side of things), and then merge the changes with the core afterward.
A good way to look at it would be that while a fork is like tampering with the whole exterior of a car, a branch is like changing the tires.
Question 4: You’ve created a commit and pushed it, it is now public. However, you’ve noticed that there are still things that need to be changed. Can you do so in this stage of the commit? And if yes, how?
Probably some of the most popular Git interview questions out there are those that require you to imagine a certain situation or scenario and then tell the interviewers how you would deal with it. Employers like this type of interview questions on Git since they usually give you situations with real-life examples that they’ve experienced themselves.
To answer the question - yes, you can still change things, even if you have already pushed the commit and made it public. The way to go about this is to issue a
git revert command. It is one of the most common Git commands and is used daily by many developers out there.
What the command will do is it will act as a “patch” to the commit that you specify needs to be changed. This way, even if you’ve missed something before deploying the commit to the live version, you may still alter and fix things afterward.
Question 5: What is ‘cherry-picking’?
This might prove as one of the more difficult Git interview questions to answer since not a lot of people look into it. As a term, cherry-picking is all that commonly used between developers (at least when compared to other basic terms as “branch” or “commit”).
Cherry-picking happens when you decide to pick out some sort of a commit from one Git-based branch and then apply its features to some other branch. Now, why is this called “cherry-picking”, you might wonder? Simple - most other Git commands that are based on commit transfers are designed to copy multiple commits at a time. With cherry-picking, you choose a specific commit that you want to apply to some other branch.
Question 6: What is a ‘stash’?
In Git, stashes are some of the most beloved features by both developers and managers alike. The way that it works is that you can just throw whatever you are working on into the stash and quickly jump to another part of the project, without fear that you’ll lose any files. The stash acts as a storing unit - it saves your project and all of its related features, is that you could come back and continue working from where you left off.
Question 7: What is a Git 'stash drop'?
It is a command to use after you are done with the stashed item or you want to delete it from the list. It can remove a specific item if you include an argument or it can remove the latest added stash item by default.
Question 8: How do you resolve ‘conflicts’ in Git?
This is one of the more clever Git interview questions since it acts as a double question - to be able to answer it correctly, you, first of all, need to know what a conflict even is.
If you work on a commit and then finally decide to merge it, it checks for any duplicate changes that might be present in the commit that is currently in place. In case such duplicates are found, Git will issue a conflict - this is done because Git does not decide which changes are the right ones, and which should be discarded. If overlooked, this might impact your project in a very negative manner - this makes Git’s decision to issue a conflict a good thing.
There are common Git commands that are used to resolve a conflict (such as
git add and
git commit). Once issued, Git will then arrange the commits in order and finish the job.
Question 9: What’s the language used in Git?
One of the Git interview questions that you can expect to receive a follow-up question, so it is a good idea to come prepared.
Quite simply, Git uses the “C” language. The most probable follow-up would then be “why?”. It is quite simply the “C” language that allows Git to be exceptionally fast - something that would be very hard to achieve with some of the more high-tier programming languages.
Question 10: What’s a ‘pull request’?
You can be sure that this is going to be a Git-related term that you’re going to both hear and use a lot, especially in Git interview questions.
While a branch is a different version of the code, a pull request is when you take a repository and then make your branch out of it. After that, you make some changes and then try to merge the branch back into the main project. For obvious reasons, pull requests have to be approved by other members related to the project.
Question 11: What is the most efficient way to find a bad commit?
Although you can go through every commit while trying to find the one that’s causing you problems, no one does that. That’s because there is a command that lets you sort through commits in a fast and easy manner, making the searching process much faster and more fluid.
The command is
Question 12: Do you know what is the difference between Git and GitHub?
We already know that Git is a version control system of distributed nature that used to track changes in the source code during software development. It can be used to track any changes in any set of files.
What is important in Git interview questions to know is that GitHub, on the other hand, is a Git repository hosting service that provides a web-based graphical interface. It provides task management tools for projects, access control, and collaboration features.
Question 13: Can you name other Git repository hosting services?
The answer to that would be:
- Visual Studio Online
Question 14: Do you know what does ‘commit object’ contain?
- A set of files that represents the state of a project.
- Reference to parent ‘commit objects’.
- An SHAI name that is 40 character string that uniquely identifies the commit object.
Question 15: Do you see any advantages of using Git?
The suggestions are:
- Collaboration friendly;
- Available to any sort of projects;
- High availability;
- Easy data redundancy and replication;
- Disk utilization and network performance;
- One Git directory per repository.
Advanced Git Queries
Now that we’ve covered some of the most popular basic interview questions on Git, we can move on to the more advanced stuff. I’ll give you a few examples of some of the most commonly asked advanced Git interview questions - do keep in mind, though, that there’s a wide variety of them that you might get asked. Even though it would be almost impossible to cover all of the possible versions of these questions in this tutorial, the ones that you’ll find ahead should give you a pretty good idea of what to expect.
Question 1: What is a ‘head’?
Although not as commonly used as some other terms in this tutorial, ahead in Git is used to refer to the object of a commit. Heads are located in repositories, and each of the repositories has a default head called a “Master”. Other than the default head, a repository can have multiple different heads at a time.
Question 2: What is ‘Git CONFIG’ used for?
It is vital to know the commands while trying to nail Git interview questions. The
git config is a command can be used to configure most of the options that you’ll need while using Git. Whether it be user info or the way that the repository works - it becomes a very convenient method of configuration.
Question 3: Can broken commits be fixed?
Yes, they can. The way that you would go about fixing a broken commit is by issuing the command
git commit - amend. This command will find the broken commit and restore it’s functionality, removing the error message in the process.
Question 4: What’s the difference between ‘get’ and ‘pull’?
When you “pull” data, it is downloaded and then immediately merged with your current working files. As opposed to that, “getting” data is the way to go if you want to download it, but not yet merge the files.
So - we have reached the end of our “Git Interview Questions” tutorial. Up to this point, we have covered a big portion of the possible basic question that you might receive during your job interview, as well as some of the more notable advanced versions of the questions.
Try not to stress too much and put all of your attention to studying Git. During the interview itself, just relax and try to answer the vast majority of the questions that you get in a clear, to-the-point manner. Do elaborate if you feel like you can or if it’s appropriate for the question - your potential employers will value that.
I hope you found these Git interview questions and answers useful, and I wish you all the best in your job interview!