git fetch downloads remote changes without modifying your current branch, while git pull performs fetch and then merges or rebases those changes into your current branch.
Git Interview Questions
Use rebase to maintain a linear history for feature branches. Use merge when you want to preserve branch context and explicit merge commits.
Use git reset --soft HEAD
1 to keep changes staged, or git reset --mixed HEAD1 to keep changes unstaged in your working tree.Question 4
What is reflog used for?
reflog tracks local HEAD movements and helps recover lost commits after operations like reset, rebase, or accidental branch deletion.
cherry-pick applies selected commits from one branch to another. It is useful for hotfix backports and selectively moving changes.
Question 6
Why is .gitignore important?
.gitignore prevents generated artifacts, secrets, and local files from being tracked and accidentally committed.
Inspect conflict blocks, keep intended logic, run tests, then mark resolved files with git add and complete merge or rebase.
reset moves branch pointers and can rewrite history; revert creates a new commit that undoes earlier changes and is safer on shared branches.
Question 9
Why do small commits matter?
Small, focused commits improve code review, make bisect debugging easier, and allow safer rollbacks.
git stash temporarily stores uncommitted work so you can switch branches quickly and reapply changes later.
Question 11
What is detached HEAD state?
Detached HEAD means you are on a commit instead of a branch. New commits are not tied to a branch unless you create one.
Question 12
What are remote tracking branches?
Branches like origin/main represent remote state locally and are updated by fetch, helping compare local and remote histories.
Question 13
What does git bisect do?
git bisect performs a binary search through commits to identify the exact commit that introduced a bug.
Rename locally with git branch -m old new, push the new name, then remove the old remote branch with git push origin --delete old.
Fast-forward moves pointers without a merge commit when history is linear; non-fast-forward creates an explicit merge commit.