Git knowledge is expected at every level of software engineering: from freshers joining their first team to senior engineers leading multi-team projects. Indian product company and service IT interviews increasingly include Git questions, both as standalone technical questions and embedded in practical scenarios. This guide covers everything from the basics tested at fresher level to the advanced Git operations tested at SDE-2 and above.
Git Fundamentals Every Engineer Must Know
Git is a distributed version control system: every clone is a full repository, not just a working copy. Four areas of Git: Working directory (your files), Staging area / Index (files marked for the next commit), Local repository (your commit history), Remote repository (GitHub/GitLab/Bitbucket). Basic workflow: git add (move to staging) → git commit (save to local repo) → git push (sync to remote). The three states a file can be in: modified (changed but not staged), staged (marked for commit), committed (saved to history). Essential commands every fresher must know: git init, git clone, git status, git add, git commit, git push, git pull, git log, git diff, git stash. The difference between git pull and git fetch: git fetch downloads remote changes without merging them into your branch; git pull = git fetch + git merge (or rebase if configured). This is a common interview question: always explain the merge/rebase distinction.
Branching and Merging
Branching allows parallel development. Common branch strategies tested in interviews: Git Flow: main (production), develop (integration), feature/, release/, hotfix/* branches. Trunk-based development: single main branch, short-lived feature branches merged frequently: preferred at high-velocity product teams. GitHub Flow: simpler than Git Flow: main + feature branches, deploy from main. Merge strategies: git merge (creates a merge commit: preserves the full branch history), git merge --no-ff (always creates a merge commit even for fast-forwards), git rebase (replays commits from one branch on top of another: produces linear history, rewrites commit hashes). The critical interview question: 'When would you use merge vs rebase?' Merge preserves history and is safer for shared branches. Rebase creates cleaner linear history but rewrites commits: never rebase a published/shared branch because it rewrites history for everyone who pulled it. Conflict resolution: when Git cannot auto-merge, it marks conflict regions in the file with <<<<<<, =======, >>>>>>>. You must manually edit to the correct state and git add the resolved file.
Advanced Git Operations
Advanced Git questions distinguish experienced candidates. git cherry-pick: apply a specific commit from another branch onto your current branch. Use case: a hotfix committed to a feature branch needs to be applied to main without merging the whole feature. git bisect: binary search through commit history to find which commit introduced a bug. You mark one commit as 'good' and one as 'bad'; Git checks out the midpoint for you to test. git reflog: shows every HEAD movement in your local repository: even after git reset --hard. This is how you recover 'lost' commits. git stash: saves uncommitted changes temporarily. git stash pop restores and removes the stash. git stash list shows all stashes. Useful when you need to switch branches but aren't ready to commit. Interactive rebase (git rebase -i): lets you squash, reorder, edit, or drop commits in your branch history before pushing. Use to clean up commit history before a PR: combine multiple 'WIP' commits into one clean commit. Subtree vs submodule: both embed one repository inside another; submodules maintain a pointer to a specific commit; subtrees copy the repository content (simpler to use).
Technical interviews often include Git scenario questions. Practise explaining your Git workflow decisions clearly with HireStepX's AI mock interviewer.
Practice freeGit in Team Workflows: Practical Scenarios
Interviewers often ask scenario-based Git questions: (1) 'You pushed sensitive credentials to a public GitHub repo. What do you do?' Immediately: git filter-branch or BFG Repo Cleaner to rewrite history and remove the file. Force-push to overwrite remote history. Rotate the credentials immediately: assume they are compromised. (2) 'Your feature branch has conflicts with main. How do you resolve?' git fetch origin && git rebase origin/main (or merge), resolve conflicts file by file, git add resolved files, git rebase --continue (or commit for merge). (3) 'You need to undo the last commit but keep the changes.' git reset --soft HEAD~1 (keeps changes staged). git reset --mixed HEAD~1 (keeps changes unstaged). git reset --hard HEAD~1 (discards changes: use with caution). (4) 'How do you handle a long-running feature branch that keeps diverging from main?' Regularly rebase onto main (or merge main into the feature branch) to minimize divergence. Alternatively, use feature flags to merge partial work to main incrementally.
Frequently asked questions
Practice these questions on HireStepX