DevLabs Alliance - WhatsApp
DevLabs Alliance Logo

Q1. What is GIT?

The following set of frequently asked interview questions have been compiled to help students and professionals preparing for Certified SDET professional courses, SDET Foundation Training, Certified SDET Architect courses. You can see the full set of SDET Interview questions here.


GIT is a Distributed Version Control System (DVCS) and Source Code Management System (SCMS) which is used to track changes to a file and also allows reverting back to any particular change. It has the ability to handle small and large projects with efficiency and speed.


Q2. What is the difference between GIT and SVN?

The differences between GIT and SVN are as follows:


GITSVNGIT is a Decentralized Version Control tool.SVN is a Centralized Version Control tool. The entire repository can be cloned on the local system. Version history is stored on a server-side Repository. Commits are possible even if offline. Only online commits are allowed. Push/Pull operations are faster. Push/Pull operations are slower. Work is shared automatically on commit. Work is not shared automatically.


Q3. What are the advantages of GIT?

The advantages of GIT are as follows:


  • Data redundancy and data replication are possible.


  • Excellent network performance and disk utilization.


  • There is only one .git directory per repository.


  • Highly available service.


  • Any type of project can use GIT.


  • It is very easy to collaborate on any project.


Q4. What language is used in GIT?

C is the programming language that is used in GIT.


C ensures that the overhead of runtimes associated with high-level languages is reduced, and hence making GIT faster.


Q5. What is a repository in GIT?

A GIT repository contains a directory named as .git where it keeps all of its metadata for the repository.

All the contents of .git directory are private to GIT.


Q6. Which command is used to write a commit message?

git commit -a is used to write a commit message in GIT.


The -a is used to instruct the git to commit the new content of all tracked files that have been modified.

If any new file needs to be committed for the first time, “git add<file>” is used before git commit.


Q7. What is Staging Area or Index in GIT?

Commits can be changed, formatted and reviewed in an intermediate area, before the completion of commits.


This intermediate area is called a Staging Area or Index.

Q8. What is the difference between Git Pull and Git Fetch?

  • git fetch downloads any new data from a remote repository, but it doesn’t integrate this downloaded data into the working files.


  • git pull downloads and also merges the data from a remote repository into the working files.


  • It can merge conflicts as well if local changes are not committed.


  • git pull = git fetch + git merge


Q9. What is Git Stash?

Git Stash takes the current state of the working directory and puts it on the stack for later, and hence providing a clean working directory.


Git Stash is used when we need to switch to any other job and at the same time, we don’t want to lose our existing work.


Q10. What is Git Stash drop?

When we want to remove the stashed item from the list, then git stash drop command is used.


It removes the last added item in stash by default, and it can also remove a specific item if included as an argument.

Q11. What is the use of git clone?

The git clone command is used to create a copy of an existing GIT repository.


Git clone is the most common way used by programmers to get the copy of a central repository to a local workspace.

Q12. How to identify if a certain branch has been merged into master?

git branch –merged master : It shows all branches that are merged into master.


git branch –merged : It shows all branches that are merged into the head.


git branch –no-merged : It shows all branches that are not merged.


Q13. What is the function of git config?

The git config command is an easy way to set configuration options for GIT installations.


Git config command is used to define the behavior of a repository, user info, preferences, etc.


For e.g.: We configure global username and email address after installing GIT. However, we can set them now if we missed that step or want to make changes.


git config –global user.name “First_Name” : This will add username.


git config –global user.email “emailAddress” : This will add Email Address.


Q14. How can you create a repository in GIT?

To create a repository in GIT, create a directory for the project if it does not exist, and then run the command “git init”.


This command will create .git directory in the project directory, the directory does not need to be empty.


Q15. What is the purpose of branching in GIT?

Branching is used to create a new own branch till some commits and then can easily switch between those branches. GIT allows having multiple local branches that can be entirely independent of each other.


This will help to go to previous work, keeping the recent work intact.


Q16. How can you delete a local and remote GIT branch?

To delete a local GIT branch, the following command is used:

git branch -d branch_name


To delete a remote GIT branch, the following command is used:

git push <remote_name> –delete <branch_name>


Q17. What is the difference between ‘git remote’ and ‘git clone’?

‘git remote add’ just creates an entry into a git config that specifies a name for a particular URL.


While, ‘git clone’ creates a new directory by copying the existing remote repository into a local workspace at the particular URL.


Q18. What is the function of ‘git diff’ in GIT?

‘git diff’ is used to show the changes between commits, commit and working tree, etc.


The most common scenario to use diff is to see what changes are made after the last commit.


For e.g.:

git diff HEAD [filename] : It compares the working directory with the local repository.

git diff [filename] : It compares the working directory with Index.

git diff –cached [filename] : compare the index with local repository.


Q19. What is the function of ‘git checkout’ in GIT?

‘git checkout’ is a command that is used to update directories or specific files in the working tree with those form another branch without merging it in the whole branch.


The git checkout command operates upon three distinct entities:


Files, commits and branches.

git checkout -b <new-branch>


Q20. What is the function of ‘git rm’ in GIT?

‘git rm’ command is used to remove individual files or a collection of files.


It is used to remove files from both the staging index and the working directory.


git rm DLA/\*.txt : This will remove all .txt files that are children of DLA directory and any of its subdirectories.


Q21. What does ‘hooks’ consists of in GIT?

GIT hooks are Shell scripts that are executed before or after the corresponding GIT commands, such as: commit, push and receive.


Git hooks are a built-in feature and there is no need to

download them.


For e.g.: GIT will try to execute a post commit script after a run of the commit.


Q22. How can you fix a broken commit in GIT?

git command –amend command is used to fix a broken commit in GIT.


This command will fire the commit patch in $Editor. We just need to edit the message right on the top line of the file, save and then quit.


Q23. What is conflict in GIT?

A conflict in GIT arises when the commit that needs to be merged has some change in one file, and also the current commit has changed in the same place in that file.


In this case, GIT is not able to predict which change should take precedence.


Q24. What is ‘head’ in GIT and how many heads can be created in a repository?

A ‘head’ in a GIT is simply a reference to a commit object.


There is a default header referred to as “Master” in every repository. A repository can contain any number of heads.


Q25. What is another option for merging in GIT, and what is the syntax for the same?

‘Rebasing’ is an alternative of merging in GIT.


Syntax:

git rebase [new-commit]


Q26. What is ‘git add’ is used for in GIT?

‘git add’ is used to add file changes in the working directory to the staging area. It tells GIT that certain updates to a particular file need to be included in the next commit.


git add <file> : Stage all changes in the file for next commit.


git add <directory> : Stage all changes in directory for the next commit.


Q27. What is the use of ‘git log’ in GIT?

‘git log’ is used to find specific commits in the project history. It can be searched by date, by author, by message, by file, etc.


For e.g.:

git log –after=“yesterday”

git log –author=”DLA”


Q28. What is the use of ‘git reset’ in GIT?

‘git reset’ is used to undo all the changes in the local directory as well as in the staging area and resets it to the state of last commit.


Syntax:

git reset


Q29. What is GIT version control?

GIT version control is used to track the history of a collection of files, and it also includes the functionality to revert the collection of files to another version.


Each version captures a screenshot of the file system at a certain point of time. All files and their complete history are stored in a repository.


Q30. Mention some of the best graphical GIT client for LINUX?

Some of the best GIT client for LINUX are:


  • Smart Git
  • Git Cola
  • GIT GUI
  • qGit
  • Git-g
  • Giggle


Q31. What does commit object contain?

Commit object contains the following:


  • It contains a set of files that represent the state of a project at a given point of time.


  • It contains a reference to parent commit objects.


  • Additionally, it contains an SHAI name, a 40 character string that uniquely identifies the commit object.


Q32. What is Subgit and why subgit is used?

SubGit is a tool that is used for a smooth, stress-free SVN to GIT migration. It is a solution for a company-wide migration from SVN to GIT.


It is widely used for the following reasons:


  • It is much better than git-svn.


  • There is no requirement to change the infrastructure that is already placed.


  • It allows using all features of GIT and SVN.


  • It provides a genuine stress-free migration experience.


Q33. What is ‘git status’ used for?

‘git status’ is used to display the state of the working directory and the staging area.


It allows us to see which changes have been staged, which have not been staged, and which files aren’t being tracked by Git.


Syntax:

git status


Q34. What is the function of ‘git stash apply’?

‘git stash apply’ command is used to bring back the saved changes onto the working directory.


It is used when we want to continue working where we have left our work.


Syntax:

git stash apply


Q35. How git instaweb is used?

Git Instaweb automatically directs a web browser and runs web server with an interface into your local repository.


Q36. How do you squash last N commits into a single commit?

The following command is used to squash the last N commits of the current branch:


git rebase –i

HEAD~{N}

N= no. of commits that you want to squash.


When the above command is run, an editor will open with a list of N commits message, one per line. Each of these lines begins with the word “pick”. Replacing the word “pick” with “squash” or “s” will tell Git to combine the commit with the commit before it. Hence, set every commit in the list to be squashed except the first one to combine all N commits into one.


Q37. How can you copy a commit made in one branch to another?

cherry-pick command is used to copy a commit from one branch to another.


It allows to play back an existing commit to current location or branch.


Simply switch to the target branch and call git cherry-pick {hash of that commit}.


Q38. How do you cherry-pick a merge commit?

Cherry-pick uses diff to find the differences between branches.

Since merge commit belongs to a different branch, it has two parents and two change sets.


For e.g.:

If we have to merge commit ref 43ad64c, we have to specify -m and use parent 1 as a base:


git checkout release_branch

git cherry-pick -m 1 43ad64c


Q39. What is GIT Bisect, and what is its purpose?

Git Bisect allows finding a bad commits efficiently.


Instead of checking every single commit to find the one that introduced some particular issue into the code, git bisect allows the user to perform a sort of binary search on the entire history of the repository and hence making it easier to find a bad commit.


This command uses a binary search algorithm to find which commit in the project’s history has introduced an issue. Before the introduction of issue, the commit is referred to as ‘good’ and after the introduction of issue, it is referred to as ‘bad’.


Then this command picks a commit between those endpoints and asks what kind of commit it is. This process continues till it finds the exact commit that introduced the change.


Q40. What commands will you use to bring a new feature to the main branch?

To bring a new feature to the main branch, we can use git merge or git pull commands.


Syntax:

git merge

git pull


Q41. What is the difference between ‘git diff’ and ‘git status’?

Git diff shows the differences between various commits and also between the working directory and staging area.


Git status provides not only the details of the files to be staged in the working repository, but along with provides the status of the comparison with the origin of your branch.


Q42. How to resolve a conflict in GIT?

For resolving any conflict in GIT, we need to edit the files for fixing the conflicting changes, and then we need to run ‘git add’ command to add the resolved files.


After that, ‘git commit’ command needs to be run to commit the repaired merge.


Q43. What is meant by GIT fork?

A Git fork is simply a copy of a GIT repository.


Forking down a repository in GIT ecosystem enables to freely experiment with different changes with little or no effects on original project.


Q44. Name a few GIT repository hosting services?

Some of the popular GIT repository hosting services are:


  • GitHub
  • Bitbucket
  • GitLab


Q45. Describe various branching strategies?

Various branching strategies are as follows:


Feature Branching: A feature branch keeps all the changes for a particular feature inside a branch. When the feature is fully tested and validated, then it is merged into master.


Task Branching: In Task branching, each task is implemented on its own branch with the task key included in the branch name. With this, it is easy to see which code implements which task, just need to find the task key in the branch name.


Release Branching: We can clone a branch to form a release branch once the develop branch has acquired enough features for a release. Creating the release branch starts the next release cycle, and hence no new feature can be added after this point, only bug fixes are allowed.


Q46. Why GIT is better than SVN?

GIT is an open-source version control system, it allows running versions of a project, which shows the various changes that were made to the code overtime.


It also allows keeping backtracking if necessary and undo those changes.


In GIT, multiple developers can check out, and upload changes and then each change can be attributed to a specific developer.


Q47. What is git Is-tree?

Git Is-tree is used to represent a tree object, including the mode and name of each item and also SHA-1 value of the blob or the tree.


Q48. What is the function of ‘git push’ in GIT?

‘git push’ command is used to update new local commits on a remote repository.


Syntax:

git push


Q49. Why is it advisable to create an additional commit rather than amending an existing commit?

It is always advisable to create an additional commit rather than amending an existing commit because the amend operation will destroy the state that was previously saved in a commit.


If only the commit message needs to be changed, then it’s not an issue to amend, but if the contents are being amended, then there are more chances of eliminating some important content.


Q50. What does git pull origin master do?

A git pull origin master is used to pull the master branch from the remote repository called origin into your current branch.


This only affects the current branch and not the local master branch

Meet The Author

DevLabs Alliance Author

Admin


HOD Neoload


DevLabs Alliance TwitterDevLabs Alliance LinkedInDevLabs Alliance Instagram

Author Bio

DevLabs Alliance conducts career transformation workshops & training in Artificial Intelligence, Machine Learning, Deep Learning, Agile, DevOps, Big Data, Blockchain, Software Test Automation, Robotics Process Automation, and other cutting-edge technologies.

INQUIRY

Want To Know More


Email is valid



Phone


By tapping continuing, you agree to our Privacy Policy and Terms & Conditions

“ The hands-on projects helped our team put theory into practice. Thanks to this training, we've achieved seamless collaboration, faster releases, and a more resilient infrastructure. ”
DevLabs Alliance Blogs Page Review
Vijay Saxena

SkillAhead Solutions

Lets get started today!

and get that DREAM JOB

DevLabs Alliance Footer section
DevLabs Alliance LinkedIn ProfileDevLabs Alliance Twitter ProfileDevLabs Alliance Facebook ProfileDevLabs Alliance Facebook Profile
DevLabs Alliance Logo

USA

1603, Capitol Avenue, Suite 413A, 2659, Cheyenne, WY 82001, USA

DevLabs Alliance ISO 9001

DevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer Section

`Copyright © DevLabs Alliance. All rights Reserved`

|

Refund & Reschedule Policy

Privacy Policy

Terms of Use