Best GIT Interview Questions And Answers In 2021

Introduction

With so much development going around all the time and with so many developers collaborating on a single project, it is easy to land up in a code mess. Git is the solution to all your coding collaboration and versioning troubles. Git is the ultimate in distributed VCS, collaboration tool, and as they call themselves, the most advanced development platform in the world. Let’s look at a few of the Git Interview questions that candidates looking for a development role need to be aware of before going for an interview. Let’s begin in right earnest.

List of Git interview questions

1. According to you, what is Git?

Git is a distributed VCS, or Ver Control System introduced to eliminate the centralized vs like SVN issues. The primary advantage of distributed VCS is the ability to store local copies of the git repository. You can continue working with git even while offline allowing a great deal of flexibility.

2. What are the important differences between SVN vs Git that you have observed?

The most important difference is in the architecture of both systems. SVN was based on central control of the version repository, while Git is distributed VCS. With Git, there is a great deal of flexibility with the ability to work with local copies of the central repository and continue to work even if the system is offline. In SVN, works were not shared automatically, while Git allows for works to be shared automatically after a commit.

3. What do you understand by distributed VCS?

Distributed VCS allow for maintaining the central copy’s local repositories instead of just maintaining a single central copy on a single server. Any commit may be done through the local repository, which then gets pushed on to the central server copy with a ‘push’.

4. What are the important differences between Git and GitHub that you have understood?

Git refers to the entire system of distributed version control architecture, where versions can be stored locally and synchronized on the remote or central server. It also serves as a collaboration platform for developers on the same project. GitHub is the centralized Git repository on the cloud instead of a local or on-premises server. GitHub also provides a graphical user interface for carrying out access control, collaboration efforts and basic task management tools for all the projects uploaded.

5. How does a VCS benefit software development?

A VCS firstly lets you create various versions and store them for quick reference. You could have a working prototype delivered and versioned while you work on a future version of the same that can be merged with the primary version to reflect the new features along with the old ones after adequate testing. A VCS also allows multiple contributors to collaborate on a single branch, and all changes merging into a common version.

A VCS also allows you to store metadata about the particular version, describing the major and minor software features changes. The whole history of the project is preserved and available for review at any time. In distributed VCS, local repositories can be copied over to the central server if the server fails, making it highly fault-tolerant.

6. What are the various hosting functions in the Git repository?

GitHub, Gitlab, Bitbucket, SourceForge, GitEnterprise are the various hosting functions in the Git repository.

7. What is the commit message?

Commit message or command is used when you are ready to save the new content or modifications to the local repository. The command writes changes to the local repository, which can be then pushed to the central repository.

8. How is the broken commit fixed?

Using the git commit –amend command, any broken commit could be fixed.

9. What is a Git repository?

The repository within Git is the location where Git stores all project relevant files. There are 2 kinds of repositories in Git, local and remote or central repository.

10. How are repositories created in Git?

Within Git, create the project-specific directory if it does not exist already. Then run git init command, which creates within project directory a git directory.

11. What is a ‘bare repository’?

In Git, any directory with no work files, in other words, no tree structure, and does not contain any .git sub-folder, but contains only version control info, is called a ‘bare repository’.

12. Explain ‘conflict’ in git

A conflict within git arises when two or more branches have made edits to the same line in a code file or when files are deleted in one branch and edited in the other branch. Git highlights all kinds of conflicts and brings to the attention of the team when it occurs.

13. What does the command git ls-tree do?

The command git ls-tree lists the given tree object’s contents, including the node and name of each item and SHA-1 val of the blob or the tree.

14. Name a few Git commands and explain their usage

git rm [file]                                     deletes the file from your current working directory and stages the file for deletion.

git log lists out the version history of the current branch.

git show [commit]                                show the metadata and content changes of the specified commit.

git tag [commitID]                                tags specified commit id.

git checkout [branch name]                switch from one branch to another.

git checkout -b [branch name]                        creates a new branch and switches to the new branch.

15. How to resolve a conflict in Git?

Git conflicts can be resolved by following these basic steps

  • Identify the conflict causing files.
  • Make the necessary changes to the files to resolve the conflict.
  • Add those files using the git add command.
  • Commit the changes using the git commit command.

16. How to revert a commit that is already made public?

You can revert a commit that is already made public by following 2 methods, 

  • Remove or update the bad file in a new commit and push to the remote or centralized repository. This will update the new changes in the repository.
  • You can also make a new commit undoing all the changes using the below command.
  • git revert <name of the bad commit>

17. Explain what is SubGit?

SubGit is a tool used for migration from SVN to Git. It creates a writable Git mirror of a local or remote Subversion repository allowing you to use both Subversion and Git parallelly for as long as you like. It is possible to create a bi-directional Git-SVN repository that is a mirror of an existing Subversion repository. 

18. List the differences between Git pull and git fetch.

Git pull, update your local repository with the latest changes to the central repository on a particular branch. At the same time, git fetch achieves the same objective, just that it does so in a slightly different manner. Git fetch will pull all the new commits from the central repository into a new local repository branch. A git merge command will then be able to merge these updates into the desired target branch. A simple equation will give you a better perspective. git pull =  git fetch git merge

Conclusion

Although Git and GitHub are simple tools, they are extensively used in the software development domain for efficient versioning.

If you are interested in making a career in the Data Science domain, our 11-month in-person Postgraduate Certificate Diploma in Data Science course can help you immensely in becoming a successful Data Science professional. 

ALSO READ

Related Articles

loader
Please wait while your application is being created.
Request Callback