KNOW Top 25+ GitHub Interview Questions & Answers | 2020
GitHub Interview Questions and Answers

KNOW Top 25+ GitHub Interview Questions & Answers

Last updated on 04th Jul 2020, Blog, Interview Questions

About author

Velusamy (Sr Technical Manager )

High level Domain Expert in TOP MNCs with 10+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 16547 Ratings 943

These GitHub Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of GitHub . As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer.we are going to cover top 100 GitHub  Interview questions along with their detailed answers. We will be covering GitHub  scenario based interview questions, GitHub  interview questions for freshers as well as GitHub  interview questions and answers for experienced. 

1. What is the difference between Git and SVN?

Ans:

GitSVN
Git is a Decentralized Version Control toolSVN is a  Centralized Version Control tool
It belongs to the 3rd generation of Version Control toolsIt belongs to the 2nd generation of Version Control tools
Clients can clone entire repositories on their local systemsVersion history is stored on a server-side repository
Commits are possible even if offlineOnly online commits are allowed
Push/pull operations are fasterPush/pull operations are slower
Works are shared automatically by commitNothing is shared automatically

2. What is Git?

Ans:

I will suggest you attempt this question by first telling about the architecture of git as shown in the below diagram just try to explain the diagram by saying:

  • Git is a Distributed Version Control system(DVCS). It lets you track changes made to a file and allows you to revert back to any particular change that you wish.
  • It is a distributed architecture that provides many advantages over other Version Control Systems (VCS) like SVN. One of the major advantages is that it does not rely on a central server to store all the versions of a project’s files.
  • Instead, every developer “clones” a copy of a repository I have shown in the diagram with “Local repository” and has the full history of the project available on his hard drive. So when there is a server outage all you need to do to recover is one of your teammate’s local Git repository.
  • There is a central cloud repository where developers can commit changes and share them with other teammates.

3. What is a distributed VCS?

Ans:

  • These are the systems that don’t rely on a central server to store a project file and all its versions.
  • In Distributed VCS, every contributor can get a local copy or “clone” of the main repository.
  • As you can see in the above diagram, every programmer can maintain a local repository which is actually the copy or clone of the central repository which is present on their hard drive. They can commit and update their local repository without any hassles.
  • With an operation called “pull”, they can update their local repositories with new data from the central server and “pull” operation affects changes to the main repository from their local repository.

4. What is the difference between Git and Github?

Ans:

Git is a version control system of distributed nature that is used to track changes in source code during software development. It aids in coordinating work among programmers, but it can be used to track changes in any set of files. The main objectives of Git are speed, data integrity, and support for distributed, non-linear workflows.

GitHub is a Git repository hosting service, plus it adds many of its own features. GitHub provides a Web-based graphical interface. It also provides access control and several collaboration features, basic task management tools for every project.

5. What are the benefits of using Version Control System?

Ans:

  • With the Version Control System(VCS), all the team members are allowed to work freely on any file at any time. VCS gives you the flexibility to merge all the changes into a common version.
  • All the previous versions and variants are neatly packed up inside the VCS. You can request any version at any time as per your requirement and you’ll have a snapshot of the complete project right at hand.
  • Whenever you save a new version of your project, your VCS requires you to provide a short description of the changes that you have made. Additionally, you can see what changes are made in the file’s content. This helps you to know what changes have been made in the project and by whom.
  • A distributed VCS like Git allows all the team members to have a complete history of the project so if there is a breakdown in the central server you can use any of your teammate’s local Git repository.

6. What language is used in Git?

Ans:

Instead of just telling the name of the language, you need to tell the reason for using it as well. I will suggest you to answer this by saying:

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.

7. Mention the various Git repository hosting functions.

Ans:

  • Github
  • Gitlab
  • Bitbucket
  • SourceForge
  • GitEnterprise

8. What is a commit message?

Ans:

The command that is used to write a commit message is “git commit -a”.

Now explain about -a flag by saying -a on the command line instructs git to commit the new content of all tracked files that have been modified. Also, mention you can use “git add <file>” before git commit -a if new files need to be committed for the first time.

9. How can you fix a broken commit?

Ans:

In order to fix any broken commit, use the command “git commit –amend”. When you run this command, you can fix the broken commit message in the editor.

10. What is a repository in Git?

Ans:

Repository in Git is a place where Git stores all the files. Git can store the files either on the local repository or on the remote repository.

11. How can you create a repository in Git?

Ans:

This is probably the most frequently asked question and the answer to this is really simple.

To create a repository, create a directory for the project if it does not exist, then run the command “git init”. By running this command .git directory will be created in the project directory.

12. What is ‘bare repository’ in Git?

Ans:

A “bare” repository in Git contains information about the version control and no working files (no tree) and it doesn’t contain the special .git sub-directory. Instead, it contains all the contents of the .git sub-directory directly in the main directory itself, whereas the working directory consists of :

  • A .git subdirectory with all the Git related revision history of your repository.
  • A working tree, or checked out copies of your project files.

13. What is a ‘conflict’ in git?

Ans:

Git can handle on its own most merges by using its automatic merging features. There arises a conflict when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other. Conflicts are most likely to happen when working in a team environment.

14. How is git instaweb used?

Ans:

‘git instaweb’ is used to automatically direct a web browser and run a webserver with an interface into your local repository.

15. What is git is-tree?

Ans:

‘git is-tree’ represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.

16. Name a few Git commands and explain their usage.

Ans:

Below are some basic Git commands:

CommandFunction
git rm [file]deletes the file from your working directory and stages the deletion.
git log list the version history for the current branch.
git show [commit]  shows the metadata and content changes of the specified commit.
git tag [commitID] used to give tags to the specified commit.
git checkout [branch name]git checkout -b [branch name]used to switch from one branch to another.creates a new branch and also switches to it.

17. How to resolve a conflict in Git?

Ans:

The following steps will resolve conflict in Git-

  1. Identify the files that have caused the conflict.
  2. Make the necessary changes in the files so that conflict does not arise again.
  3. Add these files by the command git add.
  4. Finally to commit the changed file using the command git commit

18. In Git how do you revert a commit that has already been pushed and made public?

Ans:

There can be two approaches to tackle this question and make sure that you include both because any of the below options can be used depending on the situation:

  • Remove or fix the bad file in a new commit and then push it to the remote repository. This is the most obvious way to fix an error. Once you have made necessary changes to the file, then commit it to the remote repository using the command: git commit -m “commit message”
  • Also, you can create a new commit that undoes all changes that were made in the bad commit. To do this use the command

 19. What is SubGit?

Ans:

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.

Now you can also include some advantages like you can do a fast one-time import from Subversion to Git or use SubGit within Atlassian Bitbucket Server. We can use SubGit to create a bi-directional Git-SVN mirror of an existing Subversion repository. You can push to Git or commit to Subversion as per your convenience. Synchronization will be done by SubGit. 

20. What is the difference between git pull and git fetch?

Ans:

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.

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. Just to make it easy for you, remember the equation below:

Git pull = git fetch + git merge 

    Subscribe For Free Demo

    21. What is ‘staging area’ or ‘index’ in Git?

    Ans:

    That before completing the commits, it can be formatted and reviewed in an intermediate area known as ‘Staging Area’ or ‘Index’. From the diagram it is evident that every change is first verified in the staging area I have termed it as “stage file” and then that change is committed to the repository.

    22. What work is restored when the deleted branch is recovered?

    Ans:

    The files which were stashed and saved in the stash index list will be recovered back. Any untracked files will be lost. Also, it is a good idea to always stage and commit your work or stash them.

    If you want to fetch the log references of a particular branch or tag then run the command – “git reflog <ref_name>”.

    23. What is git stash?

    Ans:

    Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for some time to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is Git stash.

    Stashing takes your working directory that is, your modified tracked files and staged changes and saves it on a stack of unfinished changes that you can reapply at any time.

    24. What is the function of ‘git stash apply’?

    Ans:

    If you want to continue working where you had left your work then ‘git stash apply‘ command is used to bring back the saved changes onto your current working directory.

    25. What is the difference between the ‘git diff ’and ‘git status’?

    Ans:

    ‘git diff ’ depicts the changes between commits, commit and working tree, etc. whereas ‘git status’ shows you the difference between the working directory and the index, it is helpful in understanding a git more comprehensively. ‘git diff’ is similar to ‘git status’, the only difference is that it shows the differences between various commits and also between the working directory and index. 

    26. What is the difference between ‘git remote’ and ‘git clone’?

    Ans:

    ‘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

    27. What is git stash drop?

    Ans:

    Git ‘stash drop’ command is used to remove the stashed item. It will remove the last added stash item by default, and it can also remove a specific item if you include it as an argument.

    Now give an example.

    If you want to remove a particular stash item from the list of stashed items you can use the below commands:

    git stash list: It will display the list of stashed items like:

    stash@{0}: WIP on master: 049d078 added the index file

    stash@{1}: WIP on master: c264051 Revert “added file_size”

    stash@{2}: WIP on master: 21d80a5 added number to log

    If you want to remove an item named stash@{0} use command git stash drop stash@{0}.

    28. How do you find a list of files that have changed in a particular commit?

    Ans:

    For this answer instead of just telling the command, explain what exactly this command will do.

    To get a list file that has changed in a particular commit use the below command:

    git diff-tree -r {hash}

    Given the commit hash, this will list all the files that were changed or added in that commit. The -r flag makes the command list individual files, rather than collapsing them into root directory names only.

    You can also include the below-mentioned point, although it is totally optional but will help in impressing the interviewer.

    The output will also include some extra information, which can be easily suppressed by including two flags:

    git diff-tree –no-commit-id –name-only -r {hash}

    Here –no-commit-id will suppress the commit hashes from appearing in the output, and –name-only will only print the file names, instead of their paths.

    29. What is the function of ‘git config’?

    Ans:

    Git uses your username to associate commits with an identity. The git config command can be used to change your Git configuration, including your username.

    Now explain with an example.

    Suppose you want to give a username and email id to associate a commit with an identity so that you can know who has made a particular commit. For that I will use:

    git config –global user.name “Your Name”: This command will add a username.

    git config –global user.email “Your E-mail Address”: This command will add an email id. 

    30. What does a commit object contain?

    Ans:

    Commit object contains the following components, you should mention all the three points presented below:

    • 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 
    Course Curriculum

    Learn GitHub Training Course to Enhance Your Career

    Weekday / Weekend BatchesSee Batch Details

    31. What is the command you can use to write a commit message?

    Ans:

    The command that is used to write a commit message is “git commit –a”.  The –a on the command line instructs git to commit the new content of all tracked files that have been modified. You can use “git add<file>” before git commit –a if new files need to be committed for the first time.

    32. What are the advantages of using GIT?

    Ans:

    a)  Data redundancy and replication

    b)  High availability

    c)   Only one.git directory per repository

    d)  Superior disk utilization and network performance

    e)  Collaboration friendly

    f)   Any sort of projects can use GIT

    33.  What is the function of ‘GIT PUSH’ in GIT?

    Ans:

    ‘GIT PUSH’ updates remote refs along with associated objects.

    34. Why GIT better than Subversion?

    Ans:

    GIT is an open source version control system; it will allow you to run ‘versions’ of a project, which show the changes that were made to the code overtime also it allows you keep the backtrack if necessary and undo those changes.  Multiple developers can checkout, and upload changes and each change can then be attributed to a specific developer.

    35. How will you know in GIT if a branch has been already merged into master?

    Ans:

    Git branch—merged lists the branches that have been merged into the current branch

    Git branch—-no merged lists the branches that have not been merged

    36. What is the function of git clone?

    Ans:

    The git clone command creates a copy of an existing Git repository.  To get the copy of a central repository, ‘cloning’  is the most common way used by programmers.

    37. What is ‘head’ in git and how many heads can be created in a repository?

    Ans:

    A ‘head’ is simply a reference to a commit object. In every repository, there is a default head referred as “Master”.  A repository can contain any number of heads.

    38. What is the purpose of branching in GIT?

    Ans:

    The purpose of branching in GIT is that you can create your own branch and jump between those branches. It will allow you to go to your previous work keeping your recent work intact.

    39. What is the common branching pattern in GIT?

    Ans:

    The common way of creating branch in GIT is to maintain one as “Main“

    branch and create another branch to implement new features. This pattern is particularly useful when there are multiple developers working on a single project.

    40. How can you bring a new feature in the main branch?

    Ans:

    To bring a new feature in the main branch, you can use a command “git merge” or “git pull command”.

    41.What is the use of Staging area or Indexing in Git?

    Ans:

    From Git’s perspective, there are three areas where the file changes can be kept i.e. working directory, staging area, and repository.

    Git Areas

    First, you make changes in your project’s working directory stored on your computer file system. All the changes remain here until you add them to an intermediate area called staging area.

    You can stage the changes by executing git add . command. This staging area gives you a preview of your next commit and basically lets you fine-tune your commits. You can add or remove changes in the staging area until you are satisfied with the version you are going to commit.

    Once you verify your changes and sign off the stage changed, then you can finally commit the changes. Upon commit, they go the local repository i.e. into .git/objects directory.

    If you use Git GUI, then you will see the option to stage your changes. In the below screenshot, the file sample.txt is under unstaged changes area which means that it’s in your working directory.

    You can select a file and click on ‘stage changed’, then it will be moved in the staging area. For example, the file hello.txt is present in stage changed (will commit) area. You can verify your changes and then do a sign-off, followed by a commit.

    Git Staging

    Staging is also referred to as indexing because git maintains an index file to keep track of your file changes across these three areas. The files which are staged are currently in your index.

    When you add changes to the staging area, then the information in the index gets updated. When you do a commit, its actually what’s in the index that gets committed, and not what’s in the working directory. You can use the git status command to see what’s in the index.

    42.When is the git config command used?

    Ans:

    The git config command is used to set configuration options for your Git installation.

    For example, after you download Git, you need to use below the config commands to setup username and commit email address in Git respectively:

    $ git config –global user.name “<username>”

    $ git config –global user.email “<email id>”

    So, mainly, things like the behavior of the repository, user information and preferences can be set up with the help of this command.

    43.What are Hooks in Git?

    Ans:

    Git hooks are certain scripts that Git runs before or after an event like commit, push, update or receive. You will find the ‘hooks’ folder inside .git directory in your local repository. You will find the build-in scripts here pre-commit, post-commit, pre-push, post push.

    These scripts get executed locally before or after the occurrence of an event. You can also modify these scripts according to your needs and Git will execute the script when that particular event occurs.

    44.What is the use of git fork? How is forking different from cloning?

    Ans:

    To fork a project means to create a remote, server-side copy of the original repository. You can rename this copy, and start doing a new project around this without affecting the original project. The fork is not the core concept of Git.

    The fork operation is used by Git workflow and this idea exists longer for free and open-source software like GitHub. Generally, once you have forked the project, you will rarely contribute to the parent project again.

    45.What is a clone in GitHub?

    Ans:

    Cloning a Git repository means we can create a local copy of the code provided by the developer. You can simply do it with a command line: git clone git://github.com/facebook/facebook-ios-sdk.git . and we can have the code in the facebook-ios-sdk directory.

    46. How much space do we get on GitHub?

    Ans:

    We get a space of 1 GB but if it exceeds 1GB, we receive a polite email from GitHub Support requesting to reduce the size of the repository and scale it down. In addition, here we placed a limit of files exceeding 100 MB in size.

    47. What do you know about GitHub and its repository?

    Ans:

    It is basically a source code management system which can be considered for both small as well as large-scale software development projects. Generally, it is widely preferred for error-free and reliable computer code. Although the users can keep up the pace with SCM, it is also possible for them to add features as per their preference. A Repository is basically the directory of the Git where the metadata of the same is stored. The data might be shared or private depending on the project.

    48. How it is possible for you as a user of Git to define the information of a user, behavior of a repository as well as the information of preferences in the programming?

    Ans:

    This can simply be done with the help of a command named Git config. Although there are other methods but getting the results through the command prompt always make sure of originality and reliability. 

    49. Tell what exactly do you know about GIT stash?

    Ans:

    It is used when there is a need of storing the current state of a project so that the users can continue with the same at a later stage. There is often a need to switch to another job when one is active and developers can simply keep up the pace with such a situation with the Stash. It simply enables the users to not to lose their edits. 

    50.Name the tool that can be deployed for Git migration?

    Ans:

    SubGit

    Course Curriculum

    Get JOB Oriented GitHub Training By MNC Experts

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    51. When it comes to software development, what are the major factors the user should be careful about?

    Ans:

    The software should be developed by understanding the exact needs of the client or the task which it has to perform. It should be rich in terms of features and API. Moreover, it should be secure and reliable enough to be trusted by the organizations. There are other factors such as the length of the code and the factors that can influence the same which are also necessary to pay attention to. 

    52. How it is possible for a developer to simply update the remote references related to the different objects?

    Ans:

    This is possible through the Git PUSH. In fact, it is actually the prime function of the same. 

    53. What do you know about the significance of software development?

    Ans:

    In the century we are living in, the overall time taken to accomplish a task largely matters when it comes to corporate level. The software are powerful in saving a lot of time. Also, they impose a strict upper limit on the dependency of a task on the humans. The tasks are generally governed, controlled, monitored and accomplished by the software in the current time. Thus, the scope is software development is blooming and users should pay attention to using the best available technology of the same. 

    54. Is it possible in the Git to merge a branch into the master? How can you find the same?

    Ans:

    Yes, it is possible and the users can easily keep the pace up with the same anytime. The users can directly check the list under the branch section to know more about this. 

    55. Name any two Git repository hosting services which are common

    Ans:

    These are Visual Studio Online and Git Enterprise

    56. What is SHAI name?

    Ans:

    It is basically a string character which is responsible for the identification of the commit objects. The fact is users are free to make the changes to the default commit objects and the same is used for knowing and locating the overall changes made with a track record of the same. 

    57. Is it possible to create a repository in the Git? What is the step that needs to be performed before doing the same?

    Ans:

    Yes, it is possible and the users have to first create a directory. The same defines the project under consideration and the information related to the same. 

    58. What is branching it Git and what are its benefits?

    Ans:

    The users are free to make as many branches as they want.  A branch is nothing but a set of tasks that is created by the users. While performing any task, whenever the interrupt arrives, the user can switch to another branch on priority and can accomplish the same first. The users can easily switch to the previous branch without compromising with the anything. It actually boosts up speed and enables users to perform multiple tasks at the same time.  Branches are generally marinated as one in the Github.

    59. What is Gitlog and when you can use it?

    Ans:

    It is basically a command that can be executed when it comes to finding the history of a project according to the date, changes made, the developer who handled it and usefulness of the same. 

    Git Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    60. What is the difference between clone, fork, and branch on Git?

    Ans:

    This question is one of the unique entries among the best Git interview questions. A Git fork is a remote, server-side replica of a repository, different from the original. It is evident to note that a fork is not a Git concept and is a social paradigm. Clone in Git is a local copy of a particular remote repository. During the process of cloning, users copy the entire source repository information alongside all the branches and history. The branch is a process for the management of all changes in a single repository before merging them into the code. You can consider a branch as a thread of the development project that exists within a repository. 

    61. How is a “branch” different from a “pull request”?

    Ans:

    The difference between a branch and a pull request is one of the important DevOps interview questions for GitHub. The branch is merely a separate version of the code. A pull request becomes evident when an individual takes the repository, makes it their own branch, makes modifications, and then attempts merging that branch in another code repository. 

    62. Do you know the use of “git cherry-pick”?

    Ans:

    Commands will be a frequently occurring element in Git interview questions. The use of the “git cherry-pick” command is evident in the processes for the introduction of specific commits from a branch in a repository to another branch. The common application of “git cherry-pick” is evident in forward- or back-port of commits from a maintenance branch to a development branch. This approach is different from other approaches such as merge and rebase that generally apply various commits to another branch. 

    63. Is it reasonable to create an additional commit or modify an existing commit?

    Ans:

    Such types of entries among Git interview questions can be confusing. You need to be clear that the creation of an additional commit is favorable as compared to modifying an existing commit. Modifications can destroy the previously saved state in the commit. Amendments in the content of the commit can lead to probabilities for the elimination of crucial data. Excessive use of “git commit- amend” can lead to the growth of a small commit and accumulation of unwanted changes.

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free