Git plays a significant role in various organizations as it is one of the best source code management systems. There are more than 40 million Git users in the world today. With features such as task management and bug tracking, Git is an efficient technology used by most industry experts today. After conducting several discussions and research, we have compiled the following list of Git interview questions:

1. What is Git and why is it used?

  • Git is the most popular, open-source, widely used, and an example of distributed version control system (DVCS) used for handling the development of small and large projects in a more efficient and neat manner.
  • It is most suitable when there are multiple people working on projects as a team and is used for tracking the project changes and efficiently supports the collaboration of the development process.
  • With the help of the versioning system, the developer can identify who has made what changes and then run tests and fix bugs if any, and then do necessary feature implementation. In case of any unforeseen circumstances, the code can be reverted to any of the previously working versions thereby saving massive efforts.

Scope of Git:

  • Due to a well-established version control system and the support for collaborative work, git has garnered wide popularity not just amongst the software developers, but also among the people who do other tasks like documentation or any other collaborative work. It can seem challenging at first, but once we get the hang of git, we find that it makes our lives much simpler.
  • It has a fantastic branching system that supports nonlinear development along with keeping the developers accountable for their code. This helps in making the development process efficient and faster.

2. What is the feature of Git?

  • Distributed System: Distributed systems are those which allow the users to perform work on a project from all over the world. A distributed system holds a Central repository that can be accessed by many remote collaborators by using a Version Control System.
  • Compatibility: Git is compatible with all the Operating Systems that are being used these days. Git repositories can also access the repositories of other Version Control Systems like SVN, CVK, etc. Git can directly access the remote repositories created by these SVNs.
  • Non-linear Development: Git allows users from all over the world to perform operations on a project remotely. A user can pick up any part of the project and do the required operation and then further update the project.
  • Branching: Git allows its users to work on a line that runs parallel to the main project files. These lines are called branches. Branches in Git provide a feature to make changes in the project without affecting the original version. 
  • Lightweight: Git stores all the data from the central repository onto the local repository while cloning is done. There might be hundreds of users working on the same project and hence the data in the central repository might be very huge.
  • Speed: Since Git stores all the data related to a project in the local repository by the process of cloning, it is very much efficient to fetch data from the local repository instead of doing the same from the remote repository.
  • Open-Source: Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It is called open-source because it provides the flexibility to modify its source code according to the user’s needs.
  • Reliable & Secure.

3. What are the advantages of using GIT?

Here are some of the essential advantages of Git:

  • Data repetition and data replication are possible
  • It is a much applicable service
  • For one depository you can have only one directory of Git
  • The network performance and disk application are excellent
  • It is effortless to collaborate on any project
  • You can work on any plan within the Git

4. What is a version control system (VCS)?

A VCS keeps track of the contributions of the developers working as a team on the projects. They maintain the history of code changes done and with project evolution, it gives an upper hand to the developers to introduce new code, fix bugs, and run tests with confidence that their previously working copy could be restored at any moment in case things go wrong.

5. What is a git repository?

A repository is a file structure where git stores all the project-based files. Git can either store the files on the local or the remote repository.

6. What does git clone do?

The command creates a copy (or clone) of an existing git repository. Generally, it is used to get a copy of the remote repository to the local repository.

7. What’s the difference between Git and GitHub?

GitGitHub
Git is a softwareGitHub is a service
Git can be installed locally on the systemGitHub is hosted on the web
Provides a desktop interface called git GUIProvides a desktop interface called GitHub Desktop.
It does not support user management featuresProvides built-in user management

8. Difference Between GitLab and GitHub?

ParametersGitLabGitHub
Developed byGitLab was developed by Dmitriy Zaporozhets and Valery Sizov.GitHub was developed by Chris Wanstrath, Tom Preston-Werner, P. J. Hyett, and Scott Chacon.
Open-sourcedGitLab is open-source for community edition.GitHub is not open source.
Public RepositoryIt allows users to make a public repository.It allows users to have an unlimited free repository.
Private RepositoryGitLab also provides a free private repository.GitHub allows users to have a free private repository but with a maximum of three collaborators.
NavigationGitLab provides the feature of navigation into the repository.GitHub allows users to navigate usability.
Project AnalysisGitLab provides users to see project development charts.GitHub doesn’t have this feature yet but they can check the commit history.
AdvantagesGitLab is freely available and open is the source for the community edition an It is a cloud-native application and is highly secure.It helps us create an organized document for the project.It is used for sharing the work in front of the public.
DisadvantagesGitLab is available with many bugs and it makes the user experience sloppy. It is difficult to manage code reviews for first-timers.There is a limited private repository. It supports only Git version control.
CompanyIt is owned by GitLab Inc.It is owned by Microsoft Corporation.

9. What is a Git repository?

A 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.

10. How can you initialize a repository in Git?

If you want to initialize an empty repository to a directory in Git, you need to enter the git init command. After this command, a hidden .git folder will appear.

11. How is Git different from Subversion (SVN)?

GITSVN
Git is a distributed decentralized version control systemSVN is a centralized version control system.
Git stores content in the form of metadata.SVN stored data in the form of files.
The master contains the latest stable release.In SVN, the trunk directory has the latest stable release 
The contents of Git are hashed using the SHA-1 hash algorithm.SVN doesn’t support hashed contents. 

12. Name a few Git commands with their function.

  • 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

13. Git is a so-called “distributed” version control system. What’s the difference between a “centralized” one?

Subversion is an example of a centralized version control system: all team members work towards a single central repository, placed on a remote server. A “checkout” from this central repository will place a “working copy” on the user’s machine. This is a snapshot from a certain version of the project on his disk.

In Git, a distributed version control system, things work a little differently. Instead of a “checkout”, a Git user will “clone” a repository from a remote server. In return, they receive a full-fledged repository, not just a working copy. The user then has their own repository on their local machine – including all of the project’s history.
You can do everything on your local machine: commit, inspect the history, restore older revisions, etc. Only if you want to share your work with the world will you have to connect to a remote server.

14. What is the difference between “fetch” and “pull”?

git fetch really only downloads new data from a remote repository – but it doesn’t integrate any of this new data into your working files. Fetch is great for getting a fresh view of all the things that happened in a remote repository.

git pull, in contrast, not only downloads new data; it also directly integrates it into your current working copy files. You can think of pull it as a combination of fetch and merge (or, alternatively, rebase).

15. What is a conflict in Git?

In Git, a conflict can occur in a couple of different situations: most commonly while performing a “merge” (but possibly also when rebasing or pulling).

In most cases, Git will figure out how to integrate new changes on its own. However, there are a handful of situations where the user might have to step in and tell Git what to do.

16. What is the purpose of the GIT stash?

GIT stash takes the present state of the working file and index and puts it on the stack for the next and gives you back a clean working file. So in case you are in the middle of an object and require to jump over to the other task, and at the same time you don’t want to lose your current edits, you can use a GIT stash.

17. Why is GIT better than Subversion?

GIT is an open-source version control framework; it will enable you to run ‘adaptations’ of a task, which demonstrate the changes that were made to the code over time also it allows you to keep the backtrack if vital and fix those changes. Multiple developers can check out, and transfer changes and each change can then be attributed to a particular developer.

18. What is tagging in Git?

Tagging allows developers to mark all the important checkpoints through the course of their projects’ progress. Instead of commit IDs, tag names can be used while commits are checked out and pushed to a remote repo.

19. What is forking in Git?

A repository copy is called a fork. So, forking allows one to experiment with changes without worrying about the original project. This process is ideal for proposing changes to someone else’s projects.

20. What is the use of a Git clone?

The Git clone command lets us copy the existing Git repository. If we want to get a copy of the central repository then the best way to do it is using ‘cloning’.

21. What is the origin of Git?

Origin refers to the remote repository that a project was originally cloned from and is used instead of the original repository’s URL. This allows for easier referencing.

22. What is the git push command?

The git push command is applied for uploading content to a remote repository from a local repository. Pushing can overwrite changes, so it should be used with caution.

23. What is the git pull command?

The git pull command is for fetching and downloading content from a remote repository and integrating it with a local repository.


Practical Questions


24. What does the command git config do?

The git config the command is a convenient way to set configuration options for defining the behavior of the repository, user information and preferences, git installation-based configurations, and many such things. 

For example:
To set up your name and email address before using git commands, we can run the below commands:

git config --global user.name“<<your_name>>” 
git config --global user.email “<<your_email>>”

25. How To Create a Git Branch?

The easiest way to create a Git branch is to use the “git checkout” command with the “-b” option for a new branch. Next, you just have to specify the name of the branch you want to create.

$ git checkout -b <branch-name>

As an example, let’s say that you want to create a new Git branch from the master branch named “feature” To achieve that, you will run the “git checkout” command with the “-b” option and add “feature” as the branch name.

$ git checkout -b feature
Switched to new branch 'feature'

As you can see, by using the “git checkout” command, you are creating a new branch and you are switching to this new branch automatically.

Leave a Reply