This document contains 50 interview questions related to Git for beginner, intermediate, and advanced levels. It covers topics such as basic Git commands, branching strategies, resolving conflicts, rebasing vs merging, and integrating Git with Jenkins. For each question, it lists the question text and brief explanation or code snippets for the answer. The full document acts as a reference guide for learning and preparing for Git related technical interviews.
6. www.edureka.co
What are the advantages of using a VCS?03
Beginners Interview Questions
• Provides flexibility
• All the versions easily available
• Changes can be tracked easily
• Provides backup
7. www.edureka.co
Difference between Git and SVN
Beginners Interview Questions
Git SVN
1. Git is a Decentralized Version
Control tool
1. SVN is a Centralized Version
Control tool
2. It belongs to the 3rd generation
of Version Control tools
2. It belongs to the 2nd generation
of Version Control tools
3. Clients can clone entire
repositories on their local systems
3. Version history is stored on a
server-side repository
4. Commits are possible even if
offline
4. Only online commits are
allowed
5. Push/pull operations are faster 5. Push/pull operations are slower
6. Works are shared automatically
by commit
6. Nothing is shared automatically
04
8. www.edureka.co
Difference between Git and Github.
Beginners Interview Questions
05
GitHub is an American company that provides hosting for software
development version control using Git. It offers all of the distributed version
control and source code management(SCM) functionality of Git as well as
adding its own features.
9. www.edureka.co
What language is used in Git?
Beginners Interview Questions
06
Git uses ‘C’ language. GIT is fast, and ‘C’ language makes this
possible by reducing the overhead of run times associated with
high-level languages.
16. www.edureka.co
What is a conflict in Git?
Beginners Interview Questions
13
Git can handle on its own most merges by using its automatic merging features.
18. www.edureka.co
How do you revert a commit that has already been pushed
and made public?
Beginners Interview Questions
15
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
20. www.edureka.co
What is SubGit?
Beginners Interview Questions
16
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.
23. www.edureka.co
What is the use of git instaweb?
Beginners Interview Questions
‘git instaweb’ is used to automatically direct a web browser and run a
webserver with an interface into your local repository.
19
24. www.edureka.co
‘git is-tree’ represents a tree object including the mode and the
name of each item and the SHA-1 value of the tree.
What is git is-tree?20
Intermediate Interview Questions
26. www.edureka.co
What is Git stash?21
Intermediate Interview Questions
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.
27. www.edureka.co
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 function of git stash apply?22
Intermediate Interview Questions
28. www.edureka.co
What work is restored when the deleted branch is recovered?23
Intermediate Interview Questions
The files which were stashed and saved in the stash index list will be recovered
back. Any untracked files will be lost.
29. www.edureka.co
'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 git more comprehensively.
Explain the difference between git status and git diff24
Intermediate Interview Questions
30. www.edureka.co
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
Mention differences between git clone and git remote25
Intermediate Interview Questions
31. www.edureka.co
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.
What is git stash drop?26
Intermediate Interview Questions
32. www.edureka.co
How to find a list of files that changed during a commit?27
Intermediate Interview Questions
To get a list files that has changed in a particular commit use the
below command:
git diff-tree -r {hash}
git diff-tree --no-commit-id --name-only -r {hash}
33. www.edureka.co
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.
git config --global user.name “your name”
git config --global user.email “Your email”
What is the function of git config?28
Intermediate Interview Questions
34. www.edureka.co
What does commit object contain?29
Intermediate Interview Questions
Commit object contains the following components, you should mention all the
three points present below:
• A set of files
• Reference to parent commit objects
• An SHA-1 name
37. www.edureka.co
Explain the advantages of forking workflow.31
Intermediate Interview Questions
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.
38. www.edureka.co
How to check whether a branch has already been merged
into the master?
32
Intermediate Interview Questions
git branch --merged
git branch --no-merged
39. www.edureka.co
Why is it desirable to create an additional commit rather than
amending an existing commit?
33
Intermediate Interview Questions
1. The amend operation destroys the state that was previously saved in a
commit.
2. Growth of a small commit and acquire unrelated changes.
40. www.edureka.co
What does hook comprise of in Git?34
Intermediate Interview Questions
This directory consists of shell scripts that are activated if you run the
corresponding Git commands.
41. www.edureka.co
How do you return a commit that has just been pushed and
made open?
Intermediate Interview Questions
35
• One or more commits can be reverted through the use of git revert
• git revert HEAD~2..HEAD
• Alternatively, there is always an option to check out the state of a
particular commit from the past and commit it anew.
42. www.edureka.co
How to remove a file from Git without removing it from your
file system?
36
Intermediate Interview Questions
git reset filename # or
echo filename >> .gitignore
43. www.edureka.co
Could you explain git workflow?
Intermediate Interview Questions
To record the history of the project, Gitflow workflow employs two parallel
long-running branches - master and develop
37
50. www.edureka.co
git reset –soft HEAD~N &&
git commit
git reset –soft HEAD~N &&
git commit –edit -m”$(git log –format=%B –reverse .HEAD@{N})”
How to squash last N commits into a single commit?
Advanced Interview Questions
43
51. www.edureka.co
What is git bisect? How do you use it to determine the
source of a bug?
Advanced Interview Questions
44
git bisect <subcommand> <options>
52. www.edureka.co
Advanced Interview Questions
How to integrate git with jenkins?45
• Click on Manage Jenkins on the Jenkins
dashboard.
• Click on Manage Plugins.
• In the plugins page, click on Git and select
install without restart.
• After this got to Manage Jenkins on
Jenkins dashboard. There you will see this
plugin installed.
58. www.edureka.co
Advanced Interview Questions
How do you configure a repository to run code sanity
checking tools right before making commits?
46
Sanity or smoke test determines whether it is possible and reasonable to continue
testing.
59. www.edureka.co
Advanced Interview Questions
How do you configure a repository to run code sanity
checking tools right before making commits?
46
#!/bin/sh
files=$(git diff –cached –name-only –diff-filter=ACM | grep ‘.go$’)
if [ -z files ]; then
exit 0
fi
unfmtd=$(gofmt -l $files)
if [ -z unfmtd ]; then
exit 0
fi
echo “Some .go files are not fmt’d”
exit 1
60. www.edureka.co
What is git cherry-pick?
Advanced Interview Questions
47
• Used to introduce a particular commit from one branch within a repository
onto a different branch .
• Used to forward- or back-port commits from a maintenance branch to a
development branch
61. www.edureka.co
What is Git reflog?
Advanced Interview Questions
48
Keeps a track of every single change made in the reference of a repository.
Command: git reflog
62. www.edureka.co
How to recover a deleted branch using git reflog?
Advanced Interview Questions
49
• History log of all references
• Identify history stamp
• Recover