Git & GitHub Interview Questions: 15 Answers With Commands
Git interview questions with answers and commands: merge vs rebase, reset vs revert, cherry-pick, stash, conflicts, branching and pull requests.
Git questions appear in interviews for almost every engineering role — developers, DevOps engineers, QA automation engineers and data engineers. Freshers are asked the basics; experienced candidates get scenario questions like "You pushed a secret to the main branch. What do you do?" Interviewers want to see that you can work safely in a shared repository. Here are fifteen common questions with concise answers and commands.
1. What is Git, and how is it different from GitHub?
Git is a distributed version control system that tracks changes to files; every clone has the full history. GitHub is a hosting platform for Git repositories that adds collaboration features: pull requests, code review, issues, Actions for CI/CD, and access control. GitLab and Bitbucket are alternatives.
2. Explain the working directory, staging area and repository
The working directory has your current files. The staging area (index) holds changes you have marked for the next commit with `git add`. The repository stores committed snapshots.
3. What is the difference between git fetch and git pull?
`git fetch` downloads new commits from the remote without changing your working branch. `git pull` is `fetch` followed by a merge (or rebase, if configured) into your current branch. Fetching first lets you inspect changes before integrating them.
4. Merge vs rebase
Both integrate changes from one branch into another. Merge creates a merge commit and preserves the branching history. Rebase replays your commits on top of the target branch, producing a linear history.
Rule of thumb: rebase your own local or feature branch to keep it current; do not rebase commits that others have already pulled, because it rewrites history.
5. How do you resolve a merge conflict?
Git marks conflicting sections in the file. Edit the file to the correct final content, remove the markers, stage it and continue.
Mention that you would run tests after resolving and talk to the other author if the intent is unclear.
6. git reset vs git revert
`git reset` moves the branch pointer backwards, optionally changing the staging area and working directory (`--soft`, `--mixed`, `--hard`). It rewrites history, so use it only on unpushed commits. `git revert` creates a new commit that undoes a previous commit, which is safe on shared branches.
7. What does git stash do?
It temporarily shelves uncommitted changes so you can switch context.
8. What is cherry-pick?
`git cherry-pick <commit>` applies a specific commit from another branch onto the current branch — useful for backporting a fix to a release branch.
9. How do you undo changes to a file?
10. What is HEAD, and what is a detached HEAD?
HEAD points to the current commit, usually through a branch. A detached HEAD means you checked out a commit directly, not a branch; new commits are not on any branch unless you create one with `git switch -c new-branch`.
11. How do you find which commit introduced a bug?
`git log` and `git blame` help for simple cases. For harder ones, `git bisect` performs a binary search through history.
12. Explain a branching strategy you have used
Common answers: trunk-based development (short-lived feature branches merged frequently into main, with feature flags), GitHub Flow (feature branches plus pull requests into main, deploy from main), and Git Flow (develop, release and hotfix branches, more common for versioned releases). Explain what your team used and why.
13. What makes a good pull request?
- Small and focused on one change.
- A clear title and description: what changed, why, and how to test.
- Passing tests and CI checks.
- Linked issue or ticket.
- Screenshots for UI changes.
14. You committed a secret (API key) and pushed it. What do you do?
First, revoke or rotate the secret immediately — assume it is compromised, because removing it from history does not undo exposure. Then remove it from the code, add it to `.gitignore` or a secrets manager, and, if required, rewrite history with a tool like `git filter-repo` in coordination with the team. Mention enabling secret scanning to prevent recurrence. Interviewers want to hear "rotate first".
15. What is .gitignore, and what belongs in it?
A file listing patterns Git should not track: dependencies (`node_modules/`), build outputs (`dist/`), environment files (`.env`), logs, and editor settings. It does not untrack files already committed; use `git rm --cached` for those.
Many interviewers ask you to explain a real situation: a nasty merge conflict, a reverted release, or a time you used bisect. Prepare one short story; it shows practical experience better than definitions.
Practice
- Create a test repository and practise rebase, interactive rebase (`git rebase -i`), revert, reset and cherry-pick.
- Deliberately create a conflict and resolve it.
- Use `git reflog` to recover a "lost" commit after a reset.
- Open a pull request on a friend's repository or an open-source project.
Getting to the interview
A GitHub profile with clean repositories, clear commit messages and READMEs supports your Git answers. Make sure your resume links it and names your tools; the Algnetic ATS resume builder checks keyword fit against postings, and auto-apply keeps applications going while you prepare.
Key takeaways
- Know the core model: working directory, staging, commits, branches, remotes.
- Understand merge vs rebase and reset vs revert, and when each is safe.
- Be fluent with stash, cherry-pick, restore, bisect and reflog.
- For leaked secrets, rotate first, then clean up.
- Back answers with real situations from your work.
Let Algnetic apply to matching jobs for you · More career guides
Related guides
https://algnetic.com/blog/git-and-github-interview-questions