Top 20 Git Interview Questions and Answers 2019

In this post, we will see Git Interview Questions with Answers. Our main focus is to cover all possible questions which can be asked during the Interview.

Top 20 Git Interview Questions and Answers 2019

Questions & Answers:

Question 1: What is Git?

Git is a distributed revision control and source code management system with an emphasis on speed. The motive of Git is to manage a project or a set of files as they change over time. Git stores this information in a data structure called a Git repository. The repository is the core of Git.

To be very clear, a Git repository is the directory where all of your project files and the related metadata reside.

Question 2: Mention a few advantages of Git?

  • Git is an Open Source Distributed Version Control System.
  • Speed
  • Simplicity
  • Fully Distributed
  • Excellent support for parallel development, support for hundreds of parallel branches.
  • Integrity

Question 3: How to create a new Repository?

git init

Question 4: How to clone the Local Repository?

git clone /path/to/repository

Question 5: How to clone remote Repository?

git clone username@host:/path/to/repository

Question 6: How to add changes to Index?

git add <filename>

Question 7: How to add all changes to index?

git add*

Question 8: How delete or remove from Index?

git rm <filename>

Question 9: How to commit changes to the repository?

git commit –m “Commit message”

Question 10: How to push changes to the remote repository?

git push origin master

Question 11: How to connect a local repository to a remote Repository?

git remote add origin <server>

Question 12: How to update the local repository with remote changes?

git pull

Question 13: How to create a new branch?

git checkout –b <branch>

example: git checkout –b feature_1

Question 14: How to switch to the master branch?

git checkout master

Question 15: How to delete branch?

git branch –d <branch>

Question 16: How to push the branch to a remote repository?

git push origin <branch>

Question 17: How to merge changes from another branch?

git merge <branch>

Question 18: How to view changes between two branches?

git diff <source branch> <target branch>

example: git diff feature_1 feature_2

Question 19: How to create a tag?

git tag <tag> <commit ID>

example: git tag 2.0.0 1b2e1d75ff

Question 20: How to get commit IDs?

git log