Git interview questions
Git questions that come up in developer and DevOps interviews, with answers that show how you would work in a team.
Merge joins two branches and keeps the history as it happened, adding a merge commit when both sides have new work. Rebase replays my commits on top of another branch, giving a straight history but new commit hashes. I rebase my own local branch before opening a pull request and use merge for anything shared.
I use git revert with that commit's hash, which adds a new commit reversing it, and then push. This keeps history consistent for everyone who already pulled. I would only reset and force-push if the team agreed, because it rewrites shared history.
I run git status to see the conflicted files, open each one and decide the correct content between the conflict markers, sometimes combining both sides. Then I remove the markers, run the tests, stage the files with git add and commit. If I am unsure about the other change, I ask its author before choosing.
fetch downloads new commits from the remote and updates branches like origin/main without touching my current branch. pull does a fetch and then merges or rebases into my branch. I use fetch when I want to look at what changed before integrating it.
stash saves my uncommitted changes and gives me a clean working directory. For example, if I am halfway through a feature and a production bug comes in, I stash, switch to a fix branch, finish the fix, then switch back and run git stash pop.
I create a branch from an updated main, commit small focused changes and push the branch with -u. I open a pull request describing what changed and how to test it, respond to review comments by pushing more commits to the same branch, and merge only after approval and passing checks. Then I delete the branch.
Practise out loud. Say each answer once as written, then again in your own words with your own number or story.
Have a number ready. "My Git score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.
More in Cloud and DevOps