DevOps · Fresher-relevant
Git interview questions on branching strategies, merge vs. rebase, cherry-pick, and resolving conflicts in collaborative workflows.
What is the difference between git merge and git rebase?
Tip: Merge creates a merge commit, preserving the true branching history (non-destructive). Rebase replays your commits on top of the target branch for a linear history, but rewrites commit hashes. Rule of thumb: rebase local/private branches, never rebase shared/pushed history.
What is the difference between git fetch and git pull?
Tip: git fetch downloads remote changes into remote-tracking branches without touching your working branch. git pull is fetch + merge (or rebase with --rebase) into your current branch. Fetch lets you review before integrating; pull integrates immediately.
How do you undo commits — reset vs revert?
Tip: git revert creates a new commit that undoes a previous one — safe for shared history. git reset moves the branch pointer back: --soft keeps changes staged, --mixed unstages them, --hard discards them. Use revert on pushed commits, reset on local-only work.
What is the difference between git reset, git stash, and git checkout?
Tip: stash shelves uncommitted changes to switch context, restored later with stash pop. reset moves the branch/HEAD and optionally changes the index/working tree. checkout (or switch/restore in modern Git) switches branches or restores files. They operate on different parts of Git's three trees.
Explain a typical Git branching strategy.
Tip: Common: trunk-based (short-lived feature branches merged to main behind feature flags, fast CI/CD) or GitFlow (main, develop, feature, release, hotfix — heavier). Most modern teams prefer trunk-based with PRs and protected main for speed and fewer merge conflicts.
How do you resolve a merge conflict?
Tip: Git marks conflicting regions with <<<<<<<, =======, >>>>>>>. Edit each file to the correct combined result, remove the markers, git add the resolved files, then commit (or continue the rebase/merge). Tools like a 3-way merge editor help on complex conflicts.
What does git cherry-pick do?
Tip: cherry-pick applies the changes from a specific commit onto your current branch as a new commit — useful for porting a bug fix to a release branch without merging everything. It can cause duplicate commits if the branch is later merged, so use it deliberately.
What is the difference between the working directory, staging area, and repository?
Tip: The working directory holds your actual files. git add moves changes to the staging area (index) — a snapshot of what will be committed. git commit records the staged snapshot into the local repository. git push then publishes commits to the remote.
InterviewEra generates role-specific questions using your actual projects and skills. Get scored feedback on technical depth, clarity, and structure — free to start.