Basic Git Interview Questions (For Freshers)
These foundational questions cover core Git concepts and commands essential for beginners entering the world of version control.
1. What is a Git repository?
A Git repository is a file structure where Git stores all project-based files along with their version history. It allows developers to track changes, revert to previous versions, and collaborate efficiently.[3]
2. How does Git work at a basic level?
Git works as a distributed version control system that records snapshots of your project over time. Each commit creates a snapshot of changes, enabling tracking and reverting.[1][5]
3. What is the purpose of git add?
The git add command stages changes in the working directory for the next commit, moving files from untracked or modified state to the staging area.[1]
4. What does git status do?
git status shows the difference between the working directory and the index, displaying tracked, untracked, modified, and staged files.[3]
5. What is git commit used for?
git commit saves the staged changes to the local repository with a descriptive message, creating a new snapshot in the commit history.[4]
6. What is git push?
git push uploads local commits to a remote repository, making changes available to others.[1]
7. What is “origin” in Git?
“Origin” is the default name for the remote repository from which the local repository was cloned, used for fetches, pulls, and pushes.[2]
8. What is the purpose of the .gitignore file?
The .gitignore file specifies files and folders for Git to ignore, such as logs or temporary files, keeping the repository clean.[2]
9. How do you create a new Git repository?
Use git init to create an empty Git repository in the current directory.[3]
10. What does git clone do?
git clone downloads a complete copy of a remote repository, including all branches and history, to create a local working copy.[1]
Intermediate Git Interview Questions (1-3 Years Experience)
These questions build on basics, focusing on branching, merging, and daily workflows suitable for developers with some hands-on experience.
11. What is a branch in Git?
A branch in Git is a lightweight pointer to a specific commit. It allows parallel development without affecting the main codebase.[1]
12. How do you create and switch to a new branch?
Use git checkout -b branch-name to create and switch to a new branch in one command.[4]
13. What is the difference between git merge and git rebase?
git merge combines branches by creating a merge commit, preserving history. git rebase reapplies commits linearly onto the target branch for cleaner history.[6]
14. What is git pull?
git pull fetches changes from the remote repository and merges them into the current branch.[4]
15. What is git fetch and how does it differ from git pull?
git fetch downloads changes from remote without merging. git pull fetches and merges automatically.[7]
16. How do you view commit history in Git?
Use git log to display the commit history, or git log --oneline for a compact view.[2]
17. What does git ls-tree do?
git ls-tree returns a tree object representation of the repository, showing mode, name, and SHA-1 for each item.[3]
18. How do you rename a branch in Git?
Use git branch -m old-name new-name when on the branch, or specify the branch name.[1]
19. What is a staging area in Git?
The staging area (index) holds changes ready to be committed. git add moves files here before git commit.[4]
20. How do you undo uncommitted changes?
Use git checkout -- file to discard changes in a file, or git restore file in newer Git versions.[1]
Advanced Git Interview Questions (3-6 Years Experience)
These scenario-based and complex questions test deep Git knowledge for senior developers handling real-world challenges at companies like Atlassian or Salesforce.
21. How do you resolve merge conflicts in Git?
Identify conflicted files with git status, edit files to resolve conflicts, stage with git add, then commit the resolution.[3]
22. What is git revert and when to use it?
git revert commit-hash creates a new commit undoing changes from a specific commit, safe for shared history.[1]
23. Explain git cherry-pick.
git cherry-pick commit-hash applies specific commits from one branch to the current branch as a new commit, without full merge.[2]
24. What is a detached HEAD state and how to fix it?
Detached HEAD occurs when not on a branch. Create a new branch with git checkout -b new-branch to save work.[1]
25. How do you squash commits before pushing?
Use git rebase -i HEAD~n (interactive rebase) to squash the last n commits into fewer commits.[7]
26. What are Git configuration levels?
Git config has –local (repo), –global (user), and –system (all users) levels for settings like user.name.[1]
27. How do you recover a lost commit in Git?
Use git reflog to view recent actions and reset to the lost commit hash.[1]
28. What is git-flow and its key branches?
Git-flow is a branching model with master (production), develop (integration), feature, release, and hotfix branches.[4]
29. In a scenario at Zoho where multiple developers push to the same branch, how do you handle force push safely?
Avoid force push on shared branches; use git push --force-with-lease instead of --force to prevent overwriting others’ work.[6]
30. How would you remove a large file from Git history at Adobe’s repository?
Use git filter-branch --tree-filter 'rm -f largefile' or BFG Repo-Cleaner, then force push (with team coordination).[7]