• Home
  • DevOps
  • Top Git and GitHub Interview Questions and Answers

Top Git and GitHub Interview Questions and Answers

Last updated on Feb 18 2022
Rahul Sharma

 

Table of Contents

Top Git and GitHub Interview Questions and Answers

What is Git?

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

What is the difference between Git and GitHub?

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.

What is the difference between Git and SVN?

g1

What is a distributed VCS?

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

What are the benefits of using Version Control System?

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

What language is used in Git?

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.

Mention the various Git repository hosting functions.

  • Github
  • Gitlab
  • Bitbucket
  • SourceForge
  • GitEnterprise

What is a commit message?

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.

How can you fix a broken commit?

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.

What is a repository in Git?

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.

How can you create a repository in Git?

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.

What is ‘bare repository’ in Git?

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 :

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

What is a ‘conflict’ in git?

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.

How is git instaweb used?

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

What is git is-tree?

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

Name a few Git commands and explain their usage.

Below are some basic Git commands:

g2

How to resolve a conflict in Git?

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

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

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

git revert <name of bad commit>

What is SubGit?

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. 

What is the difference between git pull and git fetch?

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 

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

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.

g3

What work is restored when the deleted branch is recovered?

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

What is git stash?

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.

What is the function of ‘git stash apply’?

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.

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

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

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

‘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

What is git stash drop?

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@{}: WIP on master: d added the index file
stash@{}: WIP on master: c Revert “added file_size”
stash@{}: WIP on master: da added number to log

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

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

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.

What is the function of ‘git config’?

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. 

What does a commit object contain?

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- name, a character string that uniquely identifies the commit object 

Describe the branching strategies you have used.

  • Feature branching – A feature branch model keeps all of the changes for a particular feature inside of a branch. When the feature is fully tested and validated by automated tests, the branch is then merged into master.
  • Task branching – In this model, each task is implemented on its own branch with the task key included in the branch name. It is easy to see which code implements which task, just look for the task key in the branch name.
  • Release branching – Once the develop branch has acquired enough features for a release, you can clone that branch to form a Release branch. Creating this branch starts the next release cycle, so no new features can be added after this point, only bug fixes, documentation generation, and other release-oriented tasks should go in this branch. Once it is ready to ship, the release gets merged into master and tagged with a version number. In addition, it should be merged back into the develop branch, which may have progressed since the release was initiated.
  • In the end tell them that branching strategies vary from one organization to another so I know basic branching operations like delete, merge, checking out a branch, etc.

Explain the advantages of forking workflow

  • There is a fundamental difference between the forking workflow and other popular git workflows. Rather than using a single server-side to act as the “central” codebase, it gives every developer their own server-side repository. The Forking Workflow is commonly seen in public open-source projects.
  • A crucial advantage of the Forking Workflow is that contributions can be integrated without even needing everybody to push to a single central repository that leads to clean project history. Developers can push to their own server-side repositories, but only the project maintainer can push to the official repository.
  • If developers are ready to publish a local commit, then they push the commit to their own public repository and not the official one. After this, they go for a pull request with the main repository that lets the project maintainer know an update is ready to be integrated.

How will you know in Git if a branch has already been merged into master?

The answer is pretty direct.

To know if a branch has been merged into master or not you can use the below commands:

git branch –merged – It lists the branches that have been merged into the current branch.
git branch –no-merged – It lists the branches that have not been merged.

Why is it desirable to create an additional commit rather than amending an existing commit?

There are a couple of reasons for this –

  1. The amend operation destroys the state that was previously saved in a commit. If there is just the commit message being changed then that’s not a problem.  But if the contents are being amended then chances of eliminating something important remains more.
  2. Abusing “git commit- amend” can result in the growth of a small commit and acquire unrelated changes.

What does ‘hooks’ comprise of in Git?

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. 

In Git, how would you return a commit that has just been pushed and made open?

One or more commits can be reverted through the use of git revert. This command, in a true sense, creates a new commit with patches that cancel out the changes introduced in specific commits. If in case the commit that needs to be reverted has already been published or changing the repository history is not an option then in such cases, git revert can be used to revert commits. If you run the following command then it will revert the last two commits:

git revert HEAD~..HEAD

Alternatively, there is always an option to check out the state of a particular commit from the past and commit it anew.

How to remove a file from git without removing it from your file system?

One has to be careful during a git add, else you may end up adding files that you didn’t want to commit. However, git rm will remove it from both your staging area (index), as well as your file system (working tree), which may not be what you want.

Instead, use git reset:

git reset filename          # or

echo filename >> .gitingore # add it to .gitignore to avoid re-adding it

This means that git reset <paths> is exactly the opposite of git add <paths>.

What is the difference between fork, branch, and clone?

g4

What is the difference between git merge and git rebase?

To incorporate new commits into your feature branch, you use merge

  • Creates an extra merge commit every time you need to incorporate changes
  • Pollutes your feature branch history

As an alternative to merging, you can rebase the feature branch into master.

  • Incorporates all the new commits in the master branch
  • Rewrites the project history by creating brand new commits for each commit in the original branch

What is the command used to fix a broken commit?

To fix a broken commit in Git, you may use the “git commit –amend” command, which helps you combine the staged changes with the previous commits instead of creating an entirely new commit.

Can you explain the Gitflow workflow?

To record the history of the project, Gitflow workflow employs two parallel long-running branches – master and develop:

  • Master – this branch is always ready to be released on LIVE, with everything fully tested and approved (production-ready).
  • Hotfix – these branches are used to quickly patch production releases. These branches are a lot like release branches and feature branches except they’re based on master instead of develop.
  • Develop – this is the branch to which all feature branches are merged and where all tests are performed. Only when everything’s been thoroughly checked and fixed it can be merged to the master.
  • Feature – each new feature should reside in its own branch, which can be pushed to the develop branch as their parent one.

Tell me the difference between HEAD, working tree and index, in Git.

  • The working tree/working directory/workspace is the directory tree of (source) files that you are able to see and edit.
  • The index/staging area is a single, large, binary file in <baseOfRepo>/.git/index, which lists all files in the current branch, their SHA- checksums, timestamps, and the file name – it is not another directory which contains a copy of files in it.
  • HEAD is used to refer to the last commit in the currently checked-out branch.

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

  • A fork is a copy of a repository. Normally you fork a repository so that you are able to freely experiment with changes without affecting the original project. Most commonly, forks are used to either propose changes to someone else’s project or to use someone else’s project as a starting point for your own idea.
  • git cloning means pointing to an existing repository and make a copy of that repository in a new directory, at some other location. The original repository can be located on the local file system or on remote machine accessible supported protocols. The git clone command is used to create a copy of an existing Git repository.
  • In very simple words, git branches are individual projects within a git repository. Different branches within a repository can have completely different files and folders, or it could have everything the same except for some lines of code in a file.

What are the different ways you can refer to a commit?

  • In Git each commit has a unique hash. These hashes are used to identify the corresponding commits in various scenarios, for example, while trying to checkout a particular state of the code using the git checkout {hash} command.
  • Along with this, Git maintains a number of aliases to certain commits, known as refs. Also, every tag that is created in the repository effectively becomes a ref and that is exactly why you can use tags instead of committing hashes in various git commands. Git also maintains a number of special aliases that are changed based on the state of the repository, such as HEAD, FETCH_HEAD, MERGE_HEAD, etc.
  • In Git, commits are allowed to be referred to as relative to one another. In the case of merge commits, where the commit has two parents, ^ can be used to select one of the two parents, for example, HEAD^ can be used to follow the second parent.
  • And finally, refspecs are used to map local and remote branches together. However, these can also be used to refer to commits that reside on remote branches allowing one to control and manipulate them from a local git environment.

What is the difference between rebasing and merge in Git?

  • In Git, the rebase command is used to integrate changes from one branch into another. It is an alternative to the “merge” command. The difference between rebasing and merge is that rebase rewrites the commit history in order to produce a straight, linear succession of commits.
  • Merging is Git’s way of putting a forked history back together again. The git merge command helps you take the independent lines of development created by git branch and integrate them into a single branch.

Explain the difference between reverting and resetting.

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

What is git cherry-pick?

The command git cherry-pick is normally used to introduce particular commits from one branch within a repository onto a different branch. Another common use is to forward- or back-port commits from a maintenance branch to a development branch. This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch.

Consider:

git cherry-pick <commit-hash>

How do you squash the last N commits into a single commit?

There are two options to squash the last N commits into a single commit include both of the below-mentioned options in your answer

If you want to write the new commit message from scratch use the following command
git reset –soft HEAD~N &&git commit

If you want to start editing the new commit message with a concatenation of the existing commit messages then you need to extract those messages and pass them to Git commit for that I will use
git reset –soft HEAD~N &&git commit –edit -m”$(git log –format=%B –reverse .HEAD@{N})”

What is Git bisect? How can you use it to determine the source of a (regression) bug?

  • Git bisect is used to find the commit that introduced a bug by using binary search. The command for Git bisect is
    git bisect <subcommand> <options>
  • Now since you have mentioned the command above explain to them what this command will do.
  • This command uses a binary search algorithm to find which commit in your project’s history introduced a bug. You use it by first telling it a “bad” commit that is known to contain the bug, and a “good” commit that is known to be before the bug was introduced. Then Git bisect picks a commit between those two endpoints and asks you whether the selected commit is “good” or “bad”. It continues narrowing down the range until it finds the exact commit that introduced the change.

How do you configure a Git repository to run code sanity checking tools right before making commits, and preventing them if the test fails?

Sanity or smoke test determines whether it is possible and reasonable to continue testing.

Now explain how to achieve this.

This can be done with a simple script related to the pre-commit hook of the repository. The pre-commit hook is triggered right before a commit is made, even before you are required to enter a commit message. In this script, one can run other tools, such as linters and perform sanity checks on the changes being committed into the repository.

Finally, give an example, you can refer the below script:

#!/bin/sh
files=$(git diff –cached –name-only –diff-filter=ACM | grep ‘.go$’)
if [ -z files ]; then
exit
fi
unfmtd=$(gofmt -l $files)
if [ -z unfmtd ]; then
exit
fi
echo “Some .go files are not fmt’d”
exit

This script checks to see if any .go file that is about to be committed needs to be passed through the standard Go source code formatting tool gofmt. By exiting with a non-zero status, the script effectively prevents the commit from being applied to the repository.

How do you integrate Git with Jenkins?

Step : Click on the manage jenkins button on your jenkins dashboard.

Step : Click on manage jenkins plugin.

Step : In the Plugins Page

  1. Select the GIT Plugin
  2. Click on Install without restart. The plugin will take a few moments to finish downloading depending on your internet connection, and will be installed automatically.
  3. You can also select the option Download now and Install after restart In which plugin is installed after restart
  4. You will be shown a “No updates available” message if you already have the Git plugin installed.

Step : Once the plugins have been installed, go to Manage Jenkins on your Jenkins dashboard. You will see your plugins listed among the rest.

What is git reflog?

The ‘reflog’ command keeps a track of every single change made in the references (branches or tags) of a repository and keeps a log history of the branches and tags that were either created locally or checked out. Reference logs such as the commit snapshot of when the branch was created or cloned, checked-out, renamed, or any commits made on the branch are maintained by Git and listed by the ‘reflog’ command.

This command must be executed in the repository that had the lost branch. If you consider the remote repository situation, then you have to execute the reflog command on the developer’s machine who had the branch.

command: git reflog

How to recover a deleted branch using git reflog?

Step History logs of all the references

Get a list of all the local recorded history logs for all the references (‘master’, ‘uat’ and ‘prepod’) in this repository.

g5

Step : Identify the history stamp

As you can see from the above snapshot, the highlighted commit id: ebb along with the HEAD pointer index: is the one when ‘preprod’ branch was created from the current HEAD pointer pointing to your latest work.

Step Recover

If you want to recover back the ‘preprod‘ branch then use the command  ‘git checkout’ passing the HEAD pointer reference with the index id – . This is the pointer reference when ‘preprod’ branch was created long commit id highlighted in the output screenshot.

g6

How to use GitHub?

A user can use GitHub by following ways:
•Install GIT and create a GitHub account
•Create a local GIT repository
•Add a new file to the repository
•Add a file to the staging environment
•Create a commit

What Is GitHub Link?

GitHub Link is a version control repository and it also a web-based providing hosting service over the internet.
GitHub also offers:
•Distributed Version Control
•Source Code Management

What is the difference between GIT and SVN?

The difference between GIT and SVN is
•GIT is a distributed version control system (DVCS), whereas SVN is a centralized version control system.
•GIT is less preferred for handling extremely large files or frequently changing binary files while SVN can handle multiple projects stored in the same repository.
•GIT does not support commits across multiple branches or tags. Subversion allows the creation of folders at any location in the repository layout.
•GIT is unchangeable, while Subversion allows committers to treat a tag as a branch and to create multiple revisions under a taproot.

What are the different branching strategies you have used?

The different branching strategies are as follows:
.Feature branching: A feature branch model tracks all of the changes for a particular feature inside of a branch. When the feature is fully tested and validated by automated tests, the branch is then merged into master.
.Task branching: In this branching, each task is implemented on its own branch with the task key included in the branch name. It is easy to see which code implements which task, just look for the task key in the branch name.
.Release branching: Once the development branch has acquired enough features for a release, you can clone that branch to form a Release branch.

Explain GitHub Workflow?

GIT provides three key areas that are uniquely designed, to give developers lots of control over workflow:
.Working directory: It contains all the current states of files. Numerous developers can access directory when they are logged in, so collaboration is extremely easy.
.Staging Area: It indexes everything for the next commit and any files that have been added or edited since the previous save.
.GIT repository is a dedicated space where new commits are added: GIT repository maintains all the metadata, the files, and a dedicated database that tracks versions of the project.

What do you understand by the term ‘Version Control System’?

A version control system (VCS) is a system that records all changes made to a file or set of data, so a specific version may be called later if needed.

This helps ensure that all team members are working on the latest version of the file.

 

What is a Git repository?

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.

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 in the folder.

g7

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

What are the advantages of using Git?

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

What is a commit message, and how is the commit command executed?

The commit command is executed in a Git project to record the progress in the local repository. The commit command is executed only after the files to be committed have been added to the staging area using the git add command.

The command that makes it possible to write a commit message is ‘git commit -m’.

g8

Name some of the popular Git hosting repositories.

  • GitHub
  • GitLab
  • BitBucket
  • Beanstalk
  • FogBugz
  • Surround SCM
  • Buddy

After having gone through the beginner’s level of Git interview questions, let us now level up to the following intermediate questions and answers.

Explain the git push command.

The Git push command is used to push the content in a local repository to a remote repository. After a local repository has been modified, a push is executed to share the modifications with remote team members.

Explain the git pull command.

Git pull is used to fetch and merge changes from the remote repository to the local repository. Git pull is a combination of two commands: git fetch; followed by git merge.

Difference between git fetch and git pull.

g9

What is a merge conflict in Git?

A merge conflict is an event that takes place when Git is unable to resolve differences in code between the two commits automatically.

Git is able to automatically merge the changes only if the commits are on different lines or branches.

How do you resolve a merge conflict?

To resolve a merge conflict in Git, follow these steps:

  • The most simple way to resolve the conflicted file is to open it and make the required changes
  • After editing the file, we can use the git add a command to stage the new merged content
  • The final step is to create a new commit with the help of the git commit command
  • Git will create a new merge commit to finalize the merge

What is the process to revert a commit that has already been pushed and made public?

There are two processes through which you can revert a commit:

. Remove or fix the bad file in a new commit and push it to the remote repository. Then commit it to the remote repository using:

git commit –m “commit message”

. Create a new commit to undo all the changes that were made in the bad commit. Use the following command:

git revert <commit id>

What does the git reset –mixed and git merge –abort commands do?

git reset –mixed is used to undo changes made in the working directory and staging area.

git merge –abort helps stop the merge process and return back to the state before the merging began.

How do you find a list of files that has been changed in a particular commit?

The command to get a list of files that has been changed in a particular commit is:

git diff-tree –r {commit hash}

  • -r flag allows the command to list individual files
  • commit hash lists all the files that were changed or added in the commit.

Explain the different points when a merge can enter a conflicted stage.

There are two stages when a merge can enter a conflicted stage.

. Starting the merge process

  • If there are changes in the working directory of the stage area in the current project, the merge will fail to start
  • In this case, conflicts happen due to pending changes that need to be stabilized using different Git commands

. During the merge process

  • The failure during the merge process indicates that there’s a conflict between the local branch and the branch being merged
  • In this case, Git resolves as much as possible, but some things have to be fixed manually in the conflicted files

 

If you recover a deleted branch, what work is restored?

The files that were stashed and saved in the stash index can be recovered. The files that were untracked will be lost. That’s why it’s a good idea to stage and commit your work or stash them.

What’s the difference between reverting and resetting?

g10

How can you discover if a branch has already been merged or not?

There are two commands to determine these two different things.

  1. git branch –merged – Gives the list of branches that have been merged into the current branch.
  2. git branch –no-merged – Gives the list of branches that have not been merged.

What is “git cherry-pick”?

The command git cherry-pick enables you to pick up commits from a branch within a repository and apply it to another branch. This command is useful to undo changes when any commit is accidentally made to the wrong branch. Then, you can switch to the correct branch and use this command to cherry-pick the commit.

Which language is used in Git?

Git uses ‘C’ language. Git is quick, and ‘C’ language makes this possible by decreasing the overhead of run times contained with high-level languages.

What is the purpose of GIT stash?

GIT stash takes the present state of the working file and index and puts in on the stack for next and gives you back a clean working file. So in case if you are in the middle of 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 GIT stash.

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

‘GIT PUSH’ updates remote refs along with related objects

Why do we require branching in GIT?

With the help of branching, you can keep your branch, and you can also jump between the different branches. You can go to your past work while at the same time keeping your recent work intact.

What is the purpose of ‘git config’?

The ‘Git config’ is a great method to configure your choice for the Git installation. Using this command, you can describe the repository behavior, preferences, and user information.

What is the definition of “Index” or “Staging Area” in GIT?

When you are making the commits, you can make innovation to it, format it and review it in the common area known as ‘Staging Area’ or ‘Index’.

What is the purpose of the git clone?

The git clone command generates a copy of a current Git repository. To get the copy of a central repository, ‘cloning’ is the simplest way used by programmers.

What is git pull origin?

pull is a get and a consolidation. ‘git pull origin master’ brings submits from the master branch of the source remote (into the local origin/master branch), and then it combines origin/master into the branch you currently have looked out.

What does git commit a?

Git commits “records changes to the storehouse” while git push ” updates remote refs along with contained objects” So the first one is used in a network with your local repository, while the latter one is used to communicate with a remote repository.

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

Explain what is commit message?

Commit message is a component of git which shows up when you submit a change. Git gives you a content tool where you can enter the adjustments made to a commit.

What does the committed item contain?

Commit item contains the following parts; you should specify all the three presents below:

A set of records, representing to the condition of a task at a given purpose of time

References to parent commit objects

A SHAI name, a character string that uniquely distinguishes the commit object.

Describing branching systems, you have utilized?

This question is a challenge to test your branching knowledge with Git along these lines, inform them regarding how you have utilized branching in your past activity and what reason does it serves, you can refer the below mention points:

Feature Branching:

A component branch model keeps the majority of the changes for a specific element within a branch. At the point when the item is throughout tested and approved by automated tests, the branch is then converged into master.

Task Branching

In this model, each assignment is actualized on its branch with the undertaking key included in the branch name. It is anything but difficult to see which code actualizes which task, search for the task key in the branch name.

Release Branching

Once the create branch has procured enough features for a discharge, you can clone that branch to frame a Release branch. Making this branch begins the following discharge cycle so that no new features can be included after this point, just bug fixes, documentation age, and other release-oriented assignments ought to go in this branch. When it is prepared to deliver, the release gets converged into master and labeled with a form number. Likewise, it should be converged once again into creating a branch, which may have advanced since the release was started.

At last, disclose to them that branching methodologies fluctuate starting with one association then onto the next, so I realize essential branching activities like delete, merge, checking out a branch, etc.

By what method will you know in Git if a branch has just been combined into master?

The appropriate response is immediate.

To know whether a branch has been merged into master or not you can utilize the below commands:

git branch – merged It records the branches that have been merged into the present branch.

git branch – no merged It records the branches that have not been merged.

How might you fix a messed up submit?

To fix any messed up commit, you will utilize the order “git commit? Correct.” By running this direction, you can set the wrecked commit message in the editor.

Mention some of the best graphical GIT customers for LINUX?

Some of the best GIT customer for LINUX is

  1. Git Cola
  2. Smart git
  3. Git-g
  4. Git GUI
  5. Giggle
  6. qGit

What is a clone in GitHub?

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.

How much space do we get on GitHub?

We get a space of GB but if it exceeds GB, 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 MB in size.

 What do you know about GitHub and its repository?

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.

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?

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.

 Tell what exactly do you know about GIT stash?

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.

 Name the tool that can be deployed for Git migration?

SubGit

Can you tell us a few benefits of using the GitHub over other platforms?

There are a very large number of benefits that developer can easily make sure of with this approach. The very first one is the high availability of the GitHub along with an excellent support. In addition to this, all the users can simply make sure of the data replication, as well as the redundancy of the same. Moreover, the error-free outcomes are exactly what for which GitHub is widely appreciated. It is a platform independent and users can easily get the results in the desired manner without compromising with anything.  Also, it is collaboration-friendly and users can simply use it in the way they are comfortable.

 What language is considered in Git and what is the benefit of same in this approach according to you?

Git is purely based on the C and the same make sure of imposing a limit on the overhead of runtimes which are generally associated with other platforms in its class. Also, c makes it compatible with all the other domains and developer’s already existing work.

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

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.

On what projects you have already worked on which are based on Github?

This question is often asked in the IT interviews. You need to give a short or a detailed overview of the projects you have handled, the problems you faced, the outcome of the project, the benefits organization and you as a developer derived from it, the scope of the project and the time taken to complete it. Moreover, you should mention what sort of experience you derived from them.

What is the upper limit on the heads in the Gits?

There is no limit and users are free to involve any number of heads in the repository. It can be considered as a simple standard reference to a commit object. The commit object couldn’t be same for all the heads.

Tell us whatever you know about the Github development process?

It is basically nothing but quite similar to that of a life cycle of any specific software. Thus, you should have knowledge about the life cycle of software and the factors that can directly influence the same. There are actually several activities which are a part of the process and they are:

. Analysis of the requirement
. Specifications of the project
. Architecture of the software
. Real time implementation
. Testing of software
. Documentation and reporting
. Maintenance
. Training and support available with the same

Do you think GitHub is batter as compared to Subversion of same? Why or why not?

One of the best things about the Github is it’s an open-source technology where the developers are free to run the versions of their projects without worrying about anything. This is exactly what that enable the developers to have a quick review of all the changes made to the code over time. The users can also keep a track or actual code before modification. With a sub version, nothing like this is possible. Therefore, Github is a better option.

What was your biggest problem till date while working on a Github project?

Generally, the problems are quite common in any development process. Depending on the nature and type of tasks, you might have faced a lot of issues. You can mention them all here and can genuinely answer how they were actually sorted out. Problem solving is actually learning how to tackle the challenges.

How many characters are there in the SHAI name?

It is a Character String that can vary in some special cases.

Can you put the Computer software and computer program separate from one another by a simple comparison?

Basically, a computer program is nothing but the part of a programming code and the same is responsible for the successful execution of a task. On the other hand, computer software includes the code for programming including the guide on how to use it and concerned documents.

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

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

What do you know about the significance of software development?

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

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

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.

Name any two Git repository hosting services which are common

These are Visual Studio Online and Git Enterprise

What is SHAI name?

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.

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

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.

What is branching it Git and what are its benefits?

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.

What is conflict situation in the Git and how it can be solved?

Conflict is a situation when both the commits that need to be merged have changes at the same place. This often confuses the software which change should be taken into consideration and which one should be neglected. The best manner to solve this concern is to simply edit the files through the appropriate procedure.

Can you name an alternative method for performing the merging task in the Git?

This is called as Rebasing. Generally, the users don’t prefer this method and this is because it takes a lot of time for the accomplishment of a lot of tasks that matters a lot. Sometimes a lot of unexpected errors can declare their presence in case this task is not performed accurately. This is a method that is useful only for those who have a great experience in Git technology.

 What do you mean by the Commit message?

It is basically a message which you can see on the screen while working on Git whenever a change is committed. It is possible to keep a record of all the changes made by the user in an editor. The history of changes needs to be explored lately for a specific task.

How can the users enhance the functionality of a branch in Git?

It is possible to do so by adding a desired feature in any of the branches. This is generally done through a command Git merge and the best part is there is no limit on adding the features in the branch. Any branch can have any number of features.

What is a gist in Git?

Gists are a great way to share the work of any developer. They can share parts of files, full applications or single files. Anyone can access gists at https://gist.github.com. Each Gist is Git repository, which means, it can be forked, and cloned.

How can we create a gist?

Creating a gist requires a very simple process as depicted in the steps below: –

. Sign in to GitHub.
. We should the navigate to the gist home page.
. After this, we need to type an optional description and name for the gist.
. Key in the text of your gist into the gist text box.
. Following this we should select either to create a public gist or to create a secret gist.

What is a gist programming?

GitHub provides a hosting service that facilitates a web-based Git repository. It includes all the functionality of Git with additional features added in. The gist is an additional attribute added to GitHub, which facilitates the sharing of code snippets, notes, to do lists and more. We can save our Gists as secret or public in the repository.

What are the features of GitHub?

Below is the list of features of GitHub:
Creating a folder via the Web Interface: While many of us may manage GitHub repositories through the free GitHub app, GitHub has also built what they called Web Flow. It allows us to manage repositories through GitHub’s web interface.
Drag and Drop Gist Code: Gist is GitHub’s very own facility that allows you to host code snippets.
Using GitHub Command Line Interface: GitHub CLI is initiated with a hub. It brings extra commands that can be used along with the GIT commands.
Using GIT URL Shortened: To share your GitHub repository when the URL is too long.
File Finder: Besides creating new files, you can also navigate through the files in any repository quickly.
Using GitHub Emoji: Emoji’s or emoticons are tiny icons that depict an expression of some sort.
Linking Lines: To share and point out specific lines within the file of your repository.
Task Checklist: GitHub extends markdown to cater to its own need.
Map, CSV, and D Rendering: GitHub supports CSV. If you include a .csv file, GitHub will render your CSV file into an interactive tabular data format. It even allows you to search through it. Aside from CSV, GitHub will also automatically render Map with the geoJSON format and D with the STL extension.
Get Octodex: Octodex is a collection of a creative alternate version of Octocat.

So, this brings us to the end of the Git and GitHub Interview Questions blog.This Tecklearn ‘Top Git and GitHub Interview Questions and Answers’ helps you with commonly asked questions if you are looking out for a job in Git and GitHub or DevOps Domain. If you wish to learn Git and GitHub and build a career in DevOps domain, then check out our interactive Version Control with Git and GitHub Training, that comes with 24*7 support to guide you throughout your learning period.

https://www.tecklearn.com/course/version-control-with-git-and-github/

Version Control with Git and GitHub Training

About the Course

Tecklearn has specially designed this Git and GitHub Training Course to advance your skills for a successful career in this domain. The course will cover different components of Git and GitHub and how they are used in software development operations. The course consists of important concepts like: branching & merging, how to deal with conflicts, rebasing, merge strategies, Git workflows and so on. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Git.

Why Should you take Git and GitHub Training?

  • Average salary of Git and GitHub Professional is $85k – Indeed.com
  • Amazon, Google, Facebook, Microsoft, Twitter, & many other MNC’s worldwide use Git across industries.
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Git and GitHub

  • What is version control
  • Version Control System (VCS) Products
  • Types of VCS
  • What is Git
  • Why Git for your organization
  • Install Git
  • Common commands in Git
  • Working with Remote Repositories
  • GitHub
  • Git Installation
  • Git Lifecycle
  • GitHub (Push, Pull Request)
  • GitHub Workflow

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "Top Git and GitHub Interview Questions and Answers"

Leave a Message

Your email address will not be published. Required fields are marked *