Git plays a vital role in many organizations to achieve DevOps and it is a must know technology. Ans hence this makes me prepare you for the most frequently asked Git interview questions.
Q1.What is the difference between Git and SVN?
|1. Git is a Distributed version control system||1. SVN is a Centralized version control system|
|2. Git belongs to the 3rd generation of version control system||2. Svn belongs to the 2nd generation version control system|
|3. The client can clone entire repositories on their local system||3. Version history is stored on the server-side repository hence we cannot clone|
|4. We can do commit offline also||4. We can do only online commit|
|5. Push and pull operations are faster||5. Push and pull operations are slower|
|6. Works are shared automatically by commits||6. Nothing is shared automatically|
|7. Less preferred for extremely large files and frequently changes files||7. It can handle multiple projects stored in the same repository|
|8. It doe not support commits across multiple branches and tags||8. I allow the creation of folders at any location in the repository layout|
Q2. What is Git?
Git is a version control system and source code management system, which is capable of managing both small projects and large projects with the same speed and efficiency.
git add <file name>and then commit by using
git commit -a, where "-a" parameter tells Git to commit the content of all the tracked files that have been modified.
Q6.What is the function of Git Push in Git?
It updates the Remote references with associated objects.
Q7.Which language is used in Git?
Git uses C language because it reduces the Runtime.
Q7.What is the staging area in Git?
The staging area is also called as Index, where the staging area holds /keep all the files which are in the queue for next commit.
The files which are present in the staging area are not committed yet. we can move the files in and out from the staging area without affecting the git repository and its history of changes.
Q8.What is mean by stash in Git?
Stashing is nothing but temporary storage, where
git stash command temporarily stores the modified files, untracked files and staged changes made to our working directory in its stack, and we can move forward and work on something else and can come back to the previous section and work whenever we want.
Q9.What is mean by Stash Drop?
When you are done with the stashed item or want to remove it from the list, run the git ‘stash drop’ command. It will remove the last added stash item by default, and it can also remove a specific item if you include as an argument.
Q10.What is Cloning in Git?
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
Q11.What is the Function of the git config?
The git config command is a convenient way to set configuration options for your Git installation. The behavior of a repository, user info, preferences, etc. can be defined through this command.
Q13.How can you create a repository in Git?
In Git, to create a repository, First, we have to create a directory for the project if it does not exist, and then run the command
git init. By running this command a hidden folder called .git folder will be created in the project directory, the important thing is that the directory should not be empty.
Q14.What is HEAD in Git and how many heads can be created in a repository?
A Head is simply a reference to a commit object. In every repository, there is a default head referred to as Master, which always points to the last commit. A repository can contain any number of heads.
Q15.What is the purpose of branching in Git?
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.
Q16.What is the common branching pattern in Git?
The common way of creating a branch in GIT is to maintain one as the 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.
Q17.How can you bring a new feature in the main branch?
To bring a new feature in the main branch, you can use a command git merge or git pull command.
Q18.What is conflict in Git?
A conflict arises when the commit that has to be merged has some change in one place, and the current commit also has a change at the same place. Git will not be able to predict which change should take precedence.
Q19.How Can we resolve the conflict in Git?
To resolve the conflict in Git, edit the files to fix the conflicting changes and then add the resolved files by running
git add after that to commit the repaired merge, run
git commit. Git remembers that you are in the middle of a merger, so it sets the parents of the commit correctly.
Q20.Which Command did we use to delete a Branch in Git?
Once the feature branch has been merged with the main branch, the feature is no longer needed and hence we can delete that branch by using the command
git branch -d <branch name>
Q21.Which is another option for merging in Git?
Rebasing is another option for merging in Gt.
git rebase<new commit>
git rmcommand is used.
git stash applycommand is used to bring back the saved changes onto the working directory.
git logis used to find the specific commit history in the project by Author, date, and content.
git addcommand is used to add file changes in the working directory to the index or staging area.
git resetcommand is used to reset the index as well working directory to the state of your last commit.
git Is-treeused to represents a tree object including the mode and the name of each item and the SHA-1 value of the blob or the tree.
git commit --amend, by using this command we can fix the broken commit message in the editor.
Q40. What is Git fork? What is the difference between fork, branch, and clone?
Fork: Forking is nothing but creating a copy of a repository, it allows you to make changes or experiment with the changes without affecting the original project.
Difference between Fork, Branch, and Clone
|The fork is a server-side copy of a repository, distinct from the original||Branching is a new feature which is available in the modern version control system||Cloning is the process of creating a local repository by using the command line|
|The fork allows you to make changes or experiment with the changes without affecting the original project||The branch is used to store the history of commits.||Cloning a repository means downloading a copy of source code from source control|
Q41.What is the difference between a pull request and a branch?
The difference between the pull request and ranch are as follow:
|Pull operation involves updating the local version of a repository from a remote repository||Branching is a new feature which is available in the modern version control system|
|when someone takes the repository, make their own branch, does some changes, then tries to merge that branch||
A branch is just a separate version of the code
Q42.What is the difference between git pull and git fetch?
In the simplest terms, git pull does a git fetch followed by a git merge.
|Git Pull||Git Fetch|
|When you use to pull, Git tries to automatically do your work for you. It is context sensitive so Git will merge any pulled commits into the branch you are currently working in||When you fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch.|
|pull automatically merges the commits without letting you review them first. If you don’t closely manage your branches, you may run into frequent conflicts.||This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use merge.|
Q43.Explain the advantages of Forking Workflow
Advantages of Forking workflow are as follow:
Q44.What is the difference between HEAD, working tree and index, in Git?
The difference between HEAD, working tree and Index are as follow:
|HEAD is a reference to the last commit in the currently checked-out branch.||The working tree/working directory/workspace is the directory tree of (source) files that you 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 sha1 checksums, timestamps, and the file name - it is not another directory with a copy of files in it.|