Git_and_Github_Int._QA
Git_and_Github_Int._QA
1. What is Git?
Git is a version control system for tracking changes in computer files and is used to
help coordinate work among several people on a project while tracking progress over
time. In other words, it’s a tool that facilitates source code management in software
development.
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.
A version control system (VCS) records all the 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
3. What’s the difference between Git and GitHub?
Git GitHub
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.
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.
6. How is Git different from Subversion (SVN)?
GIT SVN
Git stores content in the form of metadata. SVN stored data in the form of files.
• Git commit - Commit changes to head but not to the remote repository
• Widespread acceptance
• Pull requests
Git is a fast and reliable version control system, and the language that makes this
possible is ‘C.’
Using C language reduces the overhead of run times, which are common in high-level
languages
10. What is the correct syntax to add a message to a
commit?
git init - This command helps to create an empty repository while working on a project.
The git pull origin master fetches all the changes from the master branch onto the origin
and integrates them into the local branch.
After having gone through the beginner level Git interview questions, let us now look at
intermediate GIT interview questions and answers.
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.
14. Difference between git fetch and git pull.
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.
Here are the steps that will help you resolve conflicts in Git:
• The last step is to commit the changes in the file with the help of the git
commit command.
The git ls-tree command is used to list the contents of a tree object.
19. 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:
Git clone allows you to create a local copy of the remote GitHub repository. Once you
clone a repo, you can make edits locally in your system rather than directly in the source
files of the remote repo
Let’s say you're a developer and you want to switch branches to work on something
else. The issue is you don’t want to make commits in uncompleted work, so you just
want to get back to this point later. The solution here is the Git stash.
Git stash takes your modified tracked files and saves it on a stack of unfinished
changes that you can reapply at any time. To go back to the work you can use the stash
pop.
23. 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.
The Staging Area in Git is when it starts to track and save the changes that occur in
files. These saved changes reflect in the .git directory. Staging is an intermediate area
that helps to format and review commits before their completion.
The Git Bisect command performs a binary search to detect the commit which
introduced a bug or regression in the project’s history.
Syntax: git bisect <subcommand> <options>
26. 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:
• commit hash lists all the files that were changed or added in the commit.
The git config command is used to set git configuration values on a global or local level.
It alters the configuration options in your git installation. It is generally used to set your
Git email, editor, and any aliases you want to use with the git command.
The git clean command removes the untracked files from the working directory.
SubGit is a tool that is used to migrate SVN to Git. It transforms the SVN repositories to
Git and allows you to work on both systems concurrently. It auto-syncs the SVN with
Git.
The files that were stashed and saved in the stashed index can be recovered. The files
that were untracked will be lost. Hence, it's always a good idea to stage and commit
your work or stash them.
Now let’s raise the level of difficulty with advanced Git interview questions and answers.
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.
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.
The below command will help you achieve this:
git reset -soft HEAD~N &&git commit -edit -m“$(git log -format=%B -reverse
.HEAD@{N})”
Git merge is used to incorporate new commits into your feature branch.
• Git merge creates an extra merge commit every time you need to incorporate
changes.
As an alternative to merging, you can rebase the feature branch into master.
• 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
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.
36. 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.
The Git stash drop command is used to remove a particular stash. If there’s a stash
you're no longer using or you want to remove a specific item of stash from the list, you
can use the stash commands.
Let’s say you want to delete an item named stash@{abc}; you can use the command:
Reverting Resetting
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.
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.