Top 21 Git Interview Questions and Answers for Programmers and DevOps

Hello guys, if you are preparing for Software developer interview then you should prepare for Git, one of the essential and most popular version control and source control tool in Software industry. Almost every company, both big and small are now using Git to store their source code and conduct code reviews, yes the code review is one of the main reason many organization shifted to Git. Both Github and BitBucket provides in-built code review features which also promote good software development practices. 

Nowadays most of the developer create feature branch from master and then merge it back to master for release. When you merge your code back to master, you raise PR and this is where code review kicks in. You can setup rules that a Pull Request or PR can only be merged if it has two more approvals.  All these small things really improve the software development and delivery.

If you already know Git and looking for frequently asked Git Interview questions then you have come to the right place. Earlier, I have shared best Git courses and best places to learn Git and in this article, I am going to share 20 Git interview questions with Answers. You can use these Git questions to not only check your git knowledge but also to learn and revise essential Git concepts in quick time. 

If you have used Git in your project then most likely you can answer these questions but if you cannot you can always go back and check these free Git courses to further learn and revise key git concepts, commands, and best practices. 




21 Git Command Concepts Interview Questions and Answers for Software Developers and DevOps Engineers

Without any further ado, here is a list of common git questions you can prepare for interviews. As I said, these git questions covers essential git concepts and commands and suitable for all level of programmers but particularly 1 to 3 years of experience. Experienced programmer with more than 5 years of experience which have used other source control tools like CVS, SVN, TFS, VSS, or Clearvision can also use these questions to prepare for git interviews. 


1. What is difference between merge and rebase in Git?
While both merge and rebase solves the same problem of integrating changes from one branch to another like feature branch to master and resolving conflicts but the way the do is different. git merge takes all the changes from one branch (say feature branch) and merge them into another branch (say master) in one commit.  While rebase looks for the point where the branch started to move to a new starting point. 

As per official Git document, git rebase "reapplies commits on top of another base branch” , whereas merge “joins two or more development histories together. In other words, the main difference between merge and rebase is that while merge preserves history as it happened, rebase rewrites it

Here is a nice diagram which illustrate difference between git merge and git rebase concept:

difference between git rebase and git merge



2. What is the difference between reverting and resetting? git revert vs git reset
Answer:

Git reset is a powerful command that is used to undo local changes to the state of a Git repository. Git reset operates on “The Three Trees of Git” which are, Commit History (HEAD), the Staging Index, and the Working Directory.

On the other hand, Revert command in Git creates a new commit that undoes the changes from the previous commit. This command adds a new history to the project. It does not modify the existing history.

For this reason, git revert should be used to undo changes on a public branch, and git reset should be reserved for undoing changes on a private branch.


3. What is the difference between git pull and git fetch?
Answer: Git pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository. On the other hand, git fetch is also used for the same purpose but it works in a slightly different way. 

When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new branch in your local repository. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge. Your target branch will only be updated after merging the target branch and fetched branch.

Top 20 Git Interview Questions with Answers for Programmers



4. How do you resolve conflicts in Git?
Answer:  This is one of the really important question and often asked to experienced developers. If multiple people are modifying same file and pushing their changes then there are chances of conflict. In that case you cannot merge your PR and you have to resolve conflicts. 

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.


5. What is the difference between ‘git remote’ and ‘git clone’?
Answer: ‘git remote add’ creates an entry in your git config that specifies a name for a particular URL whereas ‘git clone’ creates a new git repository by copying an existing one located at the URL

git questions and answers




6. What is Git?

Answer: 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, we can say it’s a tool that facilitates source code management in software development.


7. What is a Git repository?
Answer: 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. If you remember, Git is a distributed version control system, which means you can have your repo in your local machine and it also contain all the version of your file. When you push the changes to remote repository, it will be transferred to server and stored there as well. 

Top 20 Git Interview Questions with Answers for Programmers


8. What are some of the best graphical GIT client for LINUX?
Answer: Some of the best GIT client for LINUX are:

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

9. What are basic Git commands with their functions?
Answer:

  • 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 the head but not to the remote repository

If you need more here is a nice list of essential git commands:

git command cheatsheet



10. What are the advantages of using Git?
Answer: While there are many advantages of using Git for version control and code repository here are a couple of key advantages I remember top of my head

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


11. How can you discover if a branch has already been merged or not?
Answer: 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.




12. What are the various Git repository hosting functions?
Answer:

  • Github
  • Gitlab
  • Bitbucket
  • SourceForge
  • GitEnterprise


13. What does a commit object contain?
Answer: Commit object contains the following components:

  • A set of files, representing the state of a project at a given point of time
  • Reference to parent commit objects
  • An SHA-1 name, a 40 character string that uniquely identifies the commit object



14. What is SubGit?

Answer: SubGit is a tool for SVN to Git migration. It can create a writable Git mirror of a local or remote Subversion repository and use both Subversion and Git as long as you like.


15. What language is used in Git?
Answer: Git uses ‘C’ language. GIT is fast, and ‘C’ language makes this possible by reducing the overhead of run times associated with high-level languages.


16. What are some of the most popular Git repository hosting functions?
Answer: Below is the list of Git repository hosting functions:

  • Pikacode
  • Assembla
  • Visual Studio Online
  • GitHub
  • GitEnterprise
  • Net
  • Beanstalk
  • CloudForge
  • GitLab
  • Planio
  • Perforce
  • Fog Creek Kiln


17. What are some of the few Git repository hosting services?
Answer:

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


18. What does ‘hooks’ comprise of in Git?
Answer: This directory consists of shell scripts that are activated if you run the corresponding Git commands. For example, git will try to execute the post-commit script after you have run a commit.




19. What is the difference between Git and GitHub?
Answer: Git is a version control system that is used in the management of the source code history. GitHub, on the other hand, is a cloud-based hosting service that is used in the management of Git repositories. GitHub is designed to help in the better management of open-source projects.


20. What is the syntax for rebasing in Git?
Answer: The syntax for rebasing in Git is “git rebase [new-commit]”


21. What is the function of ‘git reset’?
Answer: The function of ‘Git Reset’ is to reset your index as well as the working directory to the state of your last commit.


That's all about the frequently asked Git interview questions and answers. Every programmer and software developer should know essential git concepts like remote repository, push, pull, fetch, squashing commits, rebase etc and those are the ones which are often asked during interviews. 

In summary, the above-mentioned questions, are the most suitable ones because they are the ones that are frequently asked in Git interviews. You will find nothing strange when you enter the interview room and therefore you just have to relax and think about the questions with answers that you have gone through above. I wish you the best of luck in your forthcoming interview.


 Other Interview Question Articles You may like to explore

Thanks for reading this article so far. All the best for your Software Engineering and Development interviews and if you have any questions which don't know answer or any doubt feel free to ask in comments.        

P. S. - If you are new to Git and Github and looking for best resources to learn both Git concepts and commands with examples then you can also checkout this list of best free Git courses for beginners. It contains best free courses to learn Git from Udemy, Coursera, and other popular websites. A great resource for beginners.


1 comment:

  1. I miss one Git question I always ask in interviews:

    "What is the difference between merge and rebase?"

    Where drawing the answer visually on a white board is an extra plus!

    This is a good question, knowing the difference is vital, especially in team projects - you don't want developers overwriting each other's commits

    ReplyDelete

Feel free to comment, ask questions if you have any doubt.