GIT Interview Guide: From Basics to Advanced Concepts

Welcome to our GIT Interview Guide, a comprehensive resource designed for both beginners and experienced developers aiming to master version control with Git. Whether you’re just starting your journey in software development or seeking to refine your skills, this guide covers fundamental Git concepts and delves into advanced topics to prepare you for GIT-related interviews.

Basic GIT Interview Questions:

1. What is Git?

  • Git is a distributed version control system used for tracking changes in source code during software development.

2. Explain the difference between Git and GitHub.

  • Git is the version control system, while GitHub is a web-based platform that provides hosting and collaboration features for Git repositories.

3. How do you initialize a new Git repository?

  • Use the command git init to initialize a new Git repository in the current directory.

4. What is a commit in Git?

  • A commit in Git represents a snapshot of changes to the repository. It includes a commit message describing the changes.

5. How do you stage changes in Git?

  • Use the command git add <file> to stage changes before committing them.

6. Explain the difference between Git pull and Git push.

  • git pull fetches changes from a remote repository and merges them into the current branch, while git push sends local changes to a remote repository.

Advanced GIT Interview Questions:

7. What is a Git branch, and how do you create one?

  • A branch in Git is a separate line of development. Use git branch <branch_name> to create a new branch, and git checkout <branch_name> to switch to it.

8. What is a Git merge, and how does it work?

  • Git merge combines changes from different branches. Use git merge <branch_name> to merge changes from <branch_name> into the current branch.

9. Explain the purpose of Git rebase.

  • Git rebase is used to combine multiple branches or alter the commit history. It provides a cleaner and linear history compared to merging.

10. How do you resolve a merge conflict in Git?

Manually edit the conflicted files, mark them as resolved using git add, and then complete the merge with git merge --continue.

11. What is Git stash used for?

git stash is used to temporarily save changes that are not ready to be committed. Stashed changes can later be reapplied or discarded.

12. Explain the Git cherry-pick command.

git cherry-pick is used to apply a specific commit from one branch to another. It copies the changes introduced by the selected commit.

13. What is Git bisect, and how does it work?

git bisect is used for binary search through commit history to find the commit where a bug was introduced. It helps identify the exact commit causing an issue.

14. How do you revert a commit in Git?

Use git revert <commit_hash> to create a new commit that undoes the changes made in the specified commit.

15. Explain the difference between Git fetch and Git pull.

git fetch downloads changes from a remote repository but does not merge them, while git pull downloads changes and immediately merges them into the current branch.

Please find below another important question and its corresponding answer.