New 61
New 61
Git favors both programmers and non-technical users by keeping track of their
project files. It enables multiple users to work together and handles large
projects efficiently.
/// _git-1
This helps ensure that all team members are working on the latest version of the
file
server
3. What is GitHub?
To provide Internet hosting for version control and software development, GitHub
makes use of Git.
GitHub
Git is a software
GitHub is a service
git-repo
taha-git
SVN
The contents of Git are hashed using the SHA-1 hash algorithm.
Using C language reduces the overhead of run times, which are common in high-level
languages.
After having gone through the beginner level Git interview questions, let us now
look at intermediate GIT interview questions and answers.
Git-push-command
Git Pull
The Git fetch command only downloads new data from a remote repository.
Git pull updates the current HEAD branch with the latest changes from the remote
server.
It does not integrate any of these new data into your working files.
Downloads new data and integrate it with the current working files.
19. GitHub, GitLab and Bitbucket are examples of git repository _______ function?
hosting. All the three are services for hosting Git repositories
Git is capable of automatically merging the changes only if the commits are on
different lines or branches.
merge-conflict.
23. 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:
1. 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:
2. Create a new commit to undo all the changes that were made in the bad commit.
Use the following command:
24. How is a bare repository different from the standard way of initializing a Git
repository?
Standard way
Bare way
Does not contain any working or checked out copy of source files.
Bare repositories store git revision history in the root folder of your repository
instead of the .git subfolder.
27. 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.
30. 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:
35. Explain these commands one by one– git status, git log, git diff, git revert
<commit>, git reset <file>.
Git status - It shows the current status of the working directory and the staging
area.
Git revert<commit> - It is used for undoing changes to a repository's commit
history.
Git log- It is a key tool for reviewing and reading the history of everything that
happens to a repository.
Git diff- It is a multi-purpose Git command that performs a diff function on Git
data sources when executed.
Git reset<file>- it is used to unstage a file.
36. What exactly is tagging in Git?
Tagging enables developers to mark all significant checkpoints as their projects
progress.
54. Explain git reflog This command is used by Git to record changes made to the
branches' tips.
55. Role of the git annotate command.
In git, it is used to track each line of the file based on the commit information.
64. State the difference between “git remote” and “got clone”?
“Git remote” allows you to create an entry in the git configuration which specify a
URL.
“Git clone” lets you create a new git repository by letting you copy it from the
current URL.
65. Difference between “pull request” and “branch”?
“Pull request” is done when you feel like changing the developer’s change to
another person's code branch. And “Branch” is just a separate version of code.
66. How might you recover a branch that has previously pushed changes in the main
repository yet has been coincidentally erased from each team member's local
machines?
We can easily recover this by seeing the latest commit of the branch in the reflog
and then going through the new branch.
68. What command helps us to know the branches merged into master and which are
not?
git branch - -merged lets us get the lost of the branches which are currently
merged into the current branch
git branch - - no- merged shows the branches which are not merged
Now let’s raise the level of difficulty with advanced Git interview questions and
answers.
Interested to learn more about Git? Check out the DevOps Engineer Master's Program
and get certified today.
Popular Git Interview Questions
70. A simple definition of Git
Git is a free and open-source distributed version control system designed to handle
everything from small to very large projects with speed and efficiency.
The distributed nature of Git allows developers to work independently and offline.
The ability to track changes helps developers to keep track of their work and
revert to previous versions if necessary.
The support for branches allows developers to experiment with new features without
affecting the main codebase.
82. What is a branch in Git?
A branch is a way to isolate development work on a particular aspect of a project.
When a branch is created, it diverges from the primary branch. It allows developers
to work on a new feature or bug fix without affecting the main codebase.
It has a straightforward learning curve. Even those new to programming can easily
learn how to use Git with just a few hours of practice.
Git is highly flexible and can be easily customized to fit the needs of any
project.
And, Git is very stable and reliable, so users can trust that their work will be
safe and sound.
87. What do you know about Git Stash?
Git stash is a powerful tool that allows you to save your changes and revert your
working directory to a previous state. This is especially useful when switching
branches or reverting to a previous commit.
And Git Stash takes a snapshot of your changes and stores them away for later use.
88. What differentiates between the commands git remote and git clone?
The main difference between the git remote and git clone commands is that the git
remote adds a remote repository as a shortcut to your current repository, while the
git clone creates an entirely new copy of a remote repository.
89. Tell me the difference between git pull and git fetch?
Both of these commands will fetch any new commits from the remote repository, but
they differ in how they handle these commits.
Git pull will merge the remote commits into the current branch, while git fetch
will simply retrieve the commits and store them in the local repository. This means
that if you have any uncommitted changes, git pull may result in merge conflicts,
while git fetch will not.
Git is a version control system that lets you track changes to your code.
GitHub is a hosting service for Git repositories. You can use GitHub to store your
code remotely, or you can use it to collaborate with other developers on a project.
91. What about Git reflog?
Git reflog is a history of all the changes made to a git repository. It is a
valuable tool for debugging and troubleshooting purposes.
And Git reflog can be used to view the history of a repository, see who made what
changes, and when those changes were made.
The first is to simply commit your changes before switching branches. This will
ensure that your changes are saved to a specific branch, and you won't have to
worry about them being lost when you switch branches.
Another way to avoid detached HEAD is to use the "git checkout" command with the "-
b" option.
94. How will you resolve conflict in Git?
To resolve a conflict in Git, you will need to first identify the source of the
conflict. Once you have identified the source of the conflict, you can use the "git
pull" command. This will pull the latest changes from the remote repository and
merge them with your local copy.
If the "git pull" command doesn't resolve the conflict, you can try the "git merge"
command. This will merge the two versions of the code manually. You will need to
resolve the conflicts manually and then commit the merged code.
There are many reasons that you might want to use Subgit,
For example, if you have a large subversion repository with a lot of history,
moving to Git can be a huge undertaking; that's where Subgit can help transition
smoother.
And if you work in an environment where subversion is the primary version control
system, using Subgit can help you keep your Git history in sync with the rest of
the team.
Advanced Git Interview Questions
96. Explain the different points when a merge can enter a conflicted stage.
There are two stages when a merge can enter a conflicted stage.
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.
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.
97. What has to be run to squash the last N commits into a single commit?
In Git, squashing commits means combining two or more commits into one.
Use the below command to write a new commit message from the beginning.
But, if you want to edit a new commit message and add the existing commit messages,
then you must extract the messages and pass them to Git commit.
git reset -soft HEAD~N &&git commit -edit -m“$(git log -format=%B -
reverse .HEAD@{N})”
Branch
Clone
The fork is the process when a copy of the repository is made. It's usually
experimentation in the project without affecting the original project. They’re used
to advise changes or take inspiration from someone else’s project.
Git branches refer to individual projects within a git repository. If there are
several branches in a repository, then each branch can have entirely different
files and folders.
feature-master
Git merge creates an extra merge commit every time you need to incorporate changes.
It pollutes your feature branch history.
As an alternative to merging, you can rebase the feature branch into master.
feature-master2
Git rebase Incorporates all the new commits in the master branch.
It rewrites the project history by creating brand new commits for each commit in
the original branch
100. 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.
101. How do you recover a deleted branch that was not merged?
To recover a deleted branch, first, you can use the git reflog command. It will
list the local recorded logs for all the references. Then, you can identify the
history stamp and recover it using the git checkout command.
Let’s say you want to delete an item named stash@{abc}; you can use the command:
Resetting
The revert command in Git is used to create a new commit that undoes the changes
made in the previous commit. When you use this command, a new history is added to
the project; the existing history is not modified.
Git reset is a command that is used to undo the local changes that have been made
to a Git repository. Git reset operates on the following: commit history, the
staging index, and the working directory.
104. How can you discover if a branch has already been merged or not?
There are two commands to determine these two different things.
git branch --merged - Returns the list of branches that have been merged into the
current branch.
git branch --no-merged - Returns the list of branches that have not been merged.