Top Git Interview Questions and Answers for 2025


In the fast-evolving world of development, Git remains the backbone of version control systems. Whether you're a beginner trying to land your first job or a senior developer preparing for a tech lead role, understanding Git is crucial.
In this blog, you'll find a curated list of Git interview questions and answers for 2025, starting from basics and moving to advanced topics. These questions are frequently asked in technical interviews for roles like frontend, backend, DevOps, and full-stack developers.
1. What is Git?
Answer:
Git is a distributed version control system used to track changes in source code. It allows multiple developers to work collaboratively while maintaining a history of changes.
2. What is the difference between Git and GitHub?
Answer:
Git is a version control system, whereas GitHub is a cloud-based hosting service for Git repositories. Git is the tool; GitHub is the platform.
3. What is a repository in Git?
Answer:
A Git repository (repo) is a storage space where your project and its version history are stored.
4. What are the basic Git commands every developer should know?
Answer:
git init
: Initialize a repositorygit add
: Add files to staginggit commit
: Save changesgit status
: Show current changesgit push
: Push to remotegit pull
: Pull from remotegit clone
: Clone a repository
5. What is the difference between git pull
and git fetch
?
Answer:
git fetch
downloads changes but doesn't merge them automatically.git pull
downloads and merges the changes from the remote to your local branch.
6. What is the difference between git merge
and git rebase
?
Answer:
git merge
: Combines two branches and creates a new merge commit.git rebase
: Moves or re-applies commits on top of another base branch, creating a cleaner history.
7. Explain the difference between git reset
and git revert
.
Answer:
git reset
: Removes commits from history. It can be dangerous for shared branches.git revert
: Creates a new commit that undoes changes from a previous commit. It is safer for public branches.
8. What is the use of .gitignore
file?
Answer:
It tells Git which files or directories to ignore when committing code, such as environment files, logs, or node_modules
.
9. How do you resolve merge conflicts in Git?
Answer:
Manually edit the conflicting files, resolve the changes, mark them as resolved using git add
, then commit.
10. What is a detached HEAD in Git?
Answer:
It means Git is not pointing to the latest commit on a branch. This happens when you checkout a commit directly instead of a branch.
11. Whatโs the difference between git checkout
and git switch
?
Answer:
git checkout
: Versatile, but used for both switching branches and restoring files.git switch
: Introduced to simplify branch switching; usegit switch
for clarity and best practice.
Example:
git switch feature-branch
12. When would you use git stash pop
vs git stash apply
?
Answer:
git stash pop
: Applies the latest stashed changes and removes them from stash history.git stash apply
: Applies changes but retains them in the stash list for later use.
Example:
git stash apply // safer git stash pop // destructive (removes stash)
13. How to revert a specific commit?
Answer:
git revert <commit-hash>
This creates a new commit that undoes the changes from the target commit.
14. Difference between soft, mixed, and hard reset in Git?
Answer:
--soft
: Moves HEAD, keeps staging area and working directory unchanged.--mixed
(default): Moves HEAD and clears staging area.--hard
: Moves HEAD and resets staging and working directory.
Example:
git reset --soft HEAD~1
15. How to undo local commits that havenโt been pushed yet?
Answer:
git reset --soft HEAD~n
Replace n
with the number of commits you want to undo.
16. How to see the commit history in Git?
Answer:
git log
You can also use:
git log --oneline --graph --all
For a visual representation.
17. How to track a remote branch in Git?
Answer:
git checkout --track origin/branch-name
18. Whatโs the difference between tracking and non-tracking branches?
Answer:
Tracking branches are linked to remote branches and can use git pull
and git push
directly. Non-tracking branches are not associated with any remote.
19. How to clean untracked files in Git?
Answer:
git clean -f # files only git clean -fd # files + directories
20. How to squash multiple commits into one?
Answer:
git rebase -i HEAD~n
Then mark commits as squash
in the interactive editor.
Final Thoughts:
Mastering Git is essential for every developer. Interviewers often assess your problem-solving ability with Git commands during real-world issues like conflict resolution, bad commits, and deployment rollbacks.
These Git interview questions and answers for 2025 will not only help you succeed in interviews but also sharpen your daily development workflow.
๐ฃ Want More?
๐ Subscribe to our newsletter for daily Laravel, Git & DevOps insights
๐ Read next: Git Workflow Strategies โ Explained Simply
๐ Read next: Advanced Git Mastery โ Second edition 2025
๐ Read next: Advanced Git Mastery โ First edition 2025
๐ Read next: Git for Intermediate โ Branching, Remotes, Undoing Changes & More
๐ Read next: Git for Beginners โ A Complete Getting Started Guide with Examples
Subscribe to my newsletter
Read articles from Laravel Daily tips directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Laravel Daily tips
Laravel Daily tips
As a FULL-Stack, TALL Stack developer, and owner of laraveldailytips.com, I am from Pakistan. My passion is to write short and useful tips and tricks that can assist other people who are trying to learn something new and helpful. Since the beginning, I have loved PHP, Laravel, VueJS, JavaScript, jQuery, and Bootstrap. I believe in hard work combined with consistency.