How to Use This Guide

These are the Git interview questions that Automation Testers and SDETs encounter most frequently during interviews.

Each answer provides a concise explanation suitable for interview revision. For complete explanations, command examples, and real-world Git workflows, refer to the linked tutorial.

For the complete learning path, begin with the Complete Git Guide.

Advertisement

Git Basics (Q1–4)

Q1. What is Git?

Git is a distributed version control system used to track code changes and enable multiple developers to collaborate without overwriting each other's work.

Learn more: Git Basics


Q2. What is the difference between Git and GitHub?

  • Git is a distributed version control system.
  • GitHub is a cloud-based platform that hosts Git repositories and provides collaboration features.

Learn more: Git Basics


Q3. What is the difference between a Local Repository and a Remote Repository?

  • A Local Repository exists on your computer.
  • A Remote Repository is the shared repository hosted on platforms such as GitHub.

Learn more: Git Basics


Q4. What does git init do?

git init initializes a new Git repository in the current directory.

Learn more: Git Basics


Core Commands (Q5–9)

Q5. What is the difference between git add and git commit?

  • git add stages changes for commit.
  • git commit permanently records the staged changes into Git history.

Learn more: Git Commands & Usage


Q6. What is the difference between git pull and git fetch?

  • git fetch downloads remote changes without merging them.
  • git pull performs both fetch and merge.

Learn more: Git Commands & Usage


Q7. What does git clone do?

git clone creates a complete local copy of a remote repository, including its branches and commit history.

Learn more: Git Commands & Usage


Q8. What is the difference between git commit -m and git commit --amend?

  • git commit -m creates a new commit.
  • git commit --amend modifies the most recent commit.

Learn more: Git Commands & Usage


Q9. How do you check Git commit history?

Use:

git log

or

git log --oneline

for a compact commit history.

Learn more: Git Commands & Usage


Branching & Merging (Q10–14)

Q10. What is a Git Branch?

A branch represents an independent line of development.

Branches can be created using:

  • git branch
  • git checkout -b
  • git switch

Learn more: Branching & Merging


Q11. What is the difference between Merge and Rebase?

  • Merge preserves branch history by creating a merge commit.
  • Rebase creates a cleaner, linear commit history by replaying commits onto another branch.

Learn more: Branching & Merging


Q12. What causes a Merge Conflict?

Merge conflicts occur when multiple branches modify the same section of a file.

Conflicts are resolved by editing the affected files, staging the changes, and completing the merge.

Learn more: Git Errors & Troubleshooting


Q13. What is the difference between Fast-Forward Merge and Three-Way Merge?

  • Fast-Forward Merge moves the branch pointer forward without creating a merge commit.
  • Three-Way Merge creates a merge commit when both branches contain independent changes.

Learn more: Branching & Merging


Q14. When should you avoid using Rebase?

Rebase should generally not be used on shared or public branches because it rewrites commit history and can disrupt collaboration.

Learn more: Rebase & Advanced Git


Undoing & Recovering (Q15–17)

Q15. What is the difference between git reset and git revert?

  • git reset moves the branch pointer and may rewrite history.
  • git revert creates a new commit that reverses an earlier commit.

git revert is typically preferred for shared branches.

Learn more: Stash, Reset & Revert


Q16. What is git stash?

git stash temporarily saves uncommitted changes, allowing developers to switch tasks without committing unfinished work.

Learn more: Stash, Reset & Revert


Q17. What is Detached HEAD? How do you recover a deleted branch?

A Detached HEAD occurs when Git points directly to a commit instead of a branch.

Deleted branches can be recovered using git reflog by locating the commit and recreating the branch.

Learn more: Git Errors & Troubleshooting


Collaboration & Advanced Git (Q18–20)

Q18. What is a Pull Request (PR)?

A Pull Request is a request to merge changes from one branch into another after code review.

GitHub refers to it as a Pull Request, while GitLab uses the term Merge Request (MR).

Learn more: GitHub & GitLab


Q19. What is Cherry-Pick?

Cherry-Pick copies a specific commit from one branch to another.

It is commonly used for hotfixes or selectively moving individual commits.

Learn more: Rebase & Advanced Git


Q20. What is Force Push? When is it safe?

Force Push overwrites remote Git history.

It should generally be used only on personal branches where no other developers are working.

Learn more: Git Errors & Troubleshooting


Bonus: Real Git Scenarios

Your real-world Git scenarios include:

  • Committing to the wrong branch
  • Moving changes between branches using Cherry-Pick or Stash
  • Resolving git push failures caused by non-fast-forward errors
  • Fixing issues after pulling broken code

Learn more: Git Real-Time Scenarios


Next Steps

Continue your Git interview preparation with:

  • Complete Git Guide
  • Complete Jenkins Guide
  • SDET Interview Guide