BlogGit Interview QuestionInterview Questions

Top 20 Git Interview Questions and Answers

Top 20 Git Interview Questions and Answers

Here are the Top 20 Git Interview Questions and Answers with Explanations — useful for freshers to advanced-level developers:


Top 20 Git Interview Questions and Answers (Explained)

1. What is Git?

Answer:
Git is a distributed version control system used to track changes in source code during software development. It allows multiple developers to work on a project simultaneously without affecting each other’s work.


2. What is the difference between Git and GitHub?

Answer:

  • Git is a local VCS for tracking changes.
  • GitHub is a cloud-based platform to host and collaborate on Git repositories.

3. What are the advantages of Git?

Answer:

  • Distributed architecture (no internet needed for local operations)
  • Branching and merging are fast and easy
  • Lightweight and high performance
  • Keeps full history of changes
  • Secure with SHA1

Top 20 Git Interview Questions and Answers

4. Explain the Git lifecycle.

Answer:
Git workflow has 3 main stages:

  • Working Directory: Files being edited
  • Staging Area (Index): Files added using git add
  • Repository: Final commits stored using git commit

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

Answer:

  • git fetch: Gets updates from remote but does not merge.
  • git pull: Fetches + automatically merges changes into your local branch.
git fetch origin
git pull origin main

6. What does git clone do?

Answer:
Clones (downloads) a repository to your local system.

git clone https://github.com/user/repo.git

7. How do you check the status of your Git repository?

Answer:
Use git status to see changes staged, unstaged, or untracked.

git status

Top 20 Git Interview Questions and Answers

8. What is a Git branch?

Answer:
A branch represents an independent line of development. Git allows multiple branches so features can be developed in isolation.


9. How do you create and switch between branches in Git?

Answer:

git branch feature     # Create
git checkout feature   # Switch
# or both in one
git checkout -b feature

10. How do you merge branches in Git?

Answer:
Switch to the target branch and merge:

git checkout main
git merge feature

11. What is a conflict in Git, and how do you resolve it?

Answer:
A merge conflict occurs when Git cannot automatically merge changes. You resolve it by editing the files manually, then:

git add conflicted-file
git commit

Top 20 Git Interview Questions and Answers

12. What is .gitignore?

Answer:
A file that tells Git which files/folders to ignore during commits. Example:

node_modules/
.env
*.log

13. What is the difference between git reset, git revert, and git checkout?

Answer:

  • git reset: Removes commits from history (destructive).
  • git revert: Undoes a commit by creating a new commit (safe).
  • git checkout: Switch branches or restore files.

14. What is a detached HEAD in Git?

Answer:
When you checkout a commit (not a branch), HEAD is “detached,” meaning you’re not on any branch. Changes here are not saved unless a branch is created.

git checkout <commit-id>

15. What is the stash command in Git?

Answer:
Temporarily saves uncommitted changes so you can work on something else.

git stash         # Save
git stash apply   # Reapply

Top 20 Git Interview Questions and Answers

16. What is git cherry-pick?

Answer:
It applies a specific commit from one branch onto another.

git cherry-pick <commit-id>

17. How do you undo the last commit?

Answer:

git reset --soft HEAD~1   # Keep changes in staging
git reset --mixed HEAD~1  # Keep changes in working dir
git reset --hard HEAD~1   # Delete changes completely

18. What is the difference between git merge and git rebase?

Answer:

  • git merge: Combines branches and keeps history.
  • git rebase: Rewrites history to linearize commits (cleaner history).

19. What is a remote repository in Git?

Answer:
A version of your project hosted on a remote server (like GitHub, GitLab).

git remote add origin <url>
git push -u origin main

20. How do you delete a Git branch?

Answer:

  • Local branch:
git branch -d branch-name
  • Remote branch:
git push origin --delete branch-name

Top 20 Git Interview Questions and Answers

✅ Bonus: Git Cheat Sheet

ActionCommand
Stage filegit add <file>
Commitgit commit -m "message"
View loggit log
View branchesgit branch
Push to remotegit push origin main
Pull from remotegit pull

Top 20 Git Interview Questions and Answers
Advanced PHP Interview Questions And Answers

Related posts

Top 50 Python Interview Questions and Answers

Engineer Robin

Laravel 11 Vue.js 3 CRUD Application with Composition API

Engineer Robin

Can AI Replace UI Developers ?

Engineer Robin

2 comments

Our Best Top 30 React.js Interview Questions and Answers - Shikshatech June 30, 2025 at 5:53 am

[…] Top 20 Git Interview Questions and Answers […]

Reply
Creative CSS Animation Building a Party Emoji with HTML and CSS - #1 Shikshatech June 30, 2025 at 11:58 am

[…] Top 20 Git Interview Questions and Answers […]

Reply

Leave a Comment