Android Git Interview Questions
Branches, rebasing, and collaboration.
50 questions in this topic · 8 sample questions below
Practice Git in the quiz engine
Sample questions
You run git reset --hard HEAD~1. Which of the three trees does this command touch?
Why: --hard resets all three: it moves HEAD, overwrites the index, and overwrites the working tree to match the target commit. The idea that --hard only moves the branch pointer is a common misconception; that describes --soft.
What is the key difference between git reset --soft HEAD~1 and git reset --mixed HEAD~1?
Why: --soft moves HEAD only, so the undone commit's changes remain staged. --mixed (the default) also resets the index, leaving the changes present but unstaged in the working tree. Neither touches the working tree files, which is why --soft does not discard anything.
How does git revert differ from git reset for undoing a commit that has already been pushed?
Why: revert introduces a new commit whose diff is the inverse of the target, leaving all prior history intact and requiring no force push. reset moves the branch pointer and would rewrite shared history, which is why revert is preferred for pushed commits.
What does git rebase --onto main feature~3 feature do?
Why: The form is git rebase --onto newbase upstream branch: commits reachable from feature but not from feature~3 are replayed onto main. It transplants only that range, unlike a plain rebase which would use the merge base as the excluded upstream.
Which statement about a fast-forward merge is correct?
Why: A fast-forward merge occurs when the target branch has no commits the source lacks, so Git just advances the pointer with no new commit. Creating a two-parent merge commit is what --no-ff forces instead.
Why might a team prefer git merge --no-ff even when a fast-forward is possible?
Why: --no-ff forces a merge commit so the branch's grouping of commits stays visible in history, which aids review and reverting a whole feature. It does not speed anything up or auto-resolve conflicts.
What does the reflog primarily let you recover?
Why: The reflog records where HEAD and branch tips pointed over time, so you can find and restore commits orphaned by reset or rebase before gc prunes them. It does not track working-tree files that were never committed, so an un-added file overwritten by checkout is not recoverable via reflog.
You are in a detached HEAD state and make several commits. What is the danger?
Why: In detached HEAD, new commits are not referenced by any branch; when you check out another branch, they become unreachable and eventually get garbage-collected. Git does allow committing in this state, so the risk is losing the work, not being blocked from it.
Practice all 50 Git questions
These 8 are a sample. The full Git bank is scored, tracks your progress, and explains every answer.
More Android interview topics
- Android Hilt interview questions
- Android Coroutines & Flow interview questions
- Android Room interview questions
- Android Design Patterns interview questions
- Android Mobile System Design interview questions
- Android Coding Interview Patterns interview questions
- Android NDK interview questions
- Android Sensors interview questions
- Android Security interview questions
- Android Jetpack Compose interview questions
- Android Canvas & Animation interview questions
- Android CI/CD interview questions
- Android Unit Testing interview questions
- Android Kotlin interview questions
- Android Retrofit interview questions
- Android Architecture interview questions
- Android Android Framework interview questions
- Android Kotlin Multiplatform interview questions
- Android WorkManager & Background interview questions
- Android Performance & Memory interview questions