Table of Contents
- 1 Introduction
- 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: How do you resolve ‘conflicts’ in Git?
- 1.8 Question 8: What’s the language used in Git?
- 1.9 Question 9: What’s a ‘pull request’?
- 1.10 Question 10: What is the most efficient way to find a bad commit?
- 2 Git Interview Questions – Advanced
- 3 Conclusions
IntroductionTo 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? 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.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 from 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. 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.
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 really 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 revertcommand. It is actually one of the most common Git commands, and is used on a daily basis 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 actually prove as one of the more difficult Git interview questions to answer since not a lot of people really 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 basically 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: 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.
git commit). Once issued, Git will then arrange the commits in order and finish the job.
Question 8: 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 simple, really – the “C” language allows Git to be exceptionally fast – something that would be very hard to achieve with some of the more high-tier programming languages.
Question 9: 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. While a branch is a different version of the code, a pull request is when you take a repository and then make your own 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 10: What is the most efficient way to find a bad commit?Although you can go through each and every commit while trying to find the one that’s causing you problems, no one really 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
Git Interview Questions – Advanced
Question 1: What is a ‘head’?Although not as commonly used as some other terms in this tutorial, a head in Git is used to refer to the object of a commit. Heads are located in repositories, and each of the repositories have 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?The
git configcommand can be used to configure most of the options that you’ll need while using Git. Whether it be user info or the way the way that the repository works – it becomes a very convenient method of configuration.
Question 3: Can broken commits be fixed?Yes, as the matter of fact, they can. They 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.