Friday, July 1, 2022

Top Git Interview Question and Answers for Automation Tester

 ****************************************************

Top 10 Basic GIT Interview Questions

*****************************************************




1. What is Git and why is it used?
Git is the most popular, open-source, widely used, and an example of distributed version control system (DVCS) used for handling the development of small and large projects in a more efficient and neat manner.
It is most suitable when there are multiple people working on projects as a team and is used for tracking the project changes and efficiently supports the collaboration of the development process.
With the help of the versioning system, the developer can identify who has made what changes and then run tests and fix bugs if any and then do necessary feature implementation. In case of any unforeseen circumstances, the code can be reverted to any of the previously working versions thereby saving huge efforts.


Scope of Git:
  •     Due to a well-established version control system and the support for collaborative work, git has garnered wide popularity not just amongst the software developers, but also among the people who do other tasks like documentation or any other collaborative work. It can seem challenging at first, but once we get the hang of git, we find that it makes our lives much simpler.
  • it has an amazing branching system that supports nonlinear development along with keeping the developers accountable for their code. This helps in making the development process efficient and faster.

2. What is a version control system (VCS)?
A VCS keeps track of the contributions of the developers working as a team on the projects. They maintain the history of code changes done and with project evolution, it gives an upper hand to the developers to introduce new code, fixes bugs, and run tests with confidence that their previously working copy could be restored at any moment in case things go wrong.


3. What is a git repository?
A repository is a file structure where git stores all the project-based files. Git can either stores the files on the local or the remote repository.


4. What does git clone do?
The command creates a copy (or clone) of an existing git repository. Generally, it is used to get a copy of the remote repository to the local repository.


5. What does the command git config do?
The git config command is a convenient way to set configuration options for defining the behavior of the repository, user information and preferences, git installation-based configurations, and many such things.
For example:
To set up your name and email address before using git commands, we can run the below commands:

  • git config --global 
          user.name “<<your_name>>” 
  • git config --global user.email “<<your_email>>”


6. Can you explain head in terms of git and also tell the number of heads that can be present in a repository?
A head is nothing but a reference to the last commit object of a branch.
For every repository, there will always be a default head referred to as “master” or now “main” (as per GitHub) but there is no restriction to the count of heads available. In other words, it can have any number of heads.
Usages:
- To go or checkout to 1 commit before the latest commit, we use git checkout HEAD~1
- To uncommit the last 3 commits without losing the changes, we first run git reset HEAD~3 . Then we can see the changes made in the last 3 commits and then update it manually and commit it finally.
- In order to uncommit the last 3 commits and also remove the changes, we can un the command: 
git reset --hard HEAD~3 . This command will completely remove all the changes.
- To look into the changes made in the last 3 commits, we can run git diff HEAD~3
- To make a new commit by reverting the last 3 commits, we can run the command: 
git revert --no-commit HEAD~3...HEAD


7. What is a conflict?
- Git usually handles feature merges automatically but sometimes while working in a team environment, there might be cases of conflicts such as: 
1. When two separate branches have changes to the same line in a file 
2. A file is deleted in one branch but has been modified in the other. These conflicts have to be solved manually a
- These conflicts have to be solved manually after discussion with the team as git will not be able to predict what and whose changes have to be given precedence 



8. What is the functionality of git ls-tree? 
This command returns a tree object representation of the current repository along with the mode and the name of each item and the SHA-1 value of the blob.


9. What does git status command do? 
git status command is used for showing the difference between the working directory and the index which is helpful for understanding git in-depth and also keep track of the tracked and non-tracked changes.


10. Define “Index”.
Before making commits to the changes done, the developer is given provision to format and review the files and make innovations to them. All these are done in the common area which is known as ‘Index’ or ‘Staging Area’.

In the above image, the “staged” status indicates the staging area and provides an opportunity for the people to evaluate changes before committing them. 


10. What does git add command do? 
  • This command adds files and changes to the index of the existing directory. 
  • You can add all changes at once using git add . command. 
  • You can add files one by one specifically using git add  <file name> command. 
  • You can add contents of a particular folder by using git add /<folder name>/ command.











No comments:

Post a Comment

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post