RMRM Full Stack & AI Engineer · All questions · Roadmaps
Tools · interview questions

Git & GitHub Interview Questions

Git is a distributed version control system; GitHub is a cloud-based hosting platform for Git repositories. These questions cover core Git commands, branching strategies, collaboration workflows, and advanced concepts commonly tested in technical interviews.

1. What is Git and how does it differ from GitHub?

beginner

Git is a distributed version control system that tracks changes in source code locally on your machine. GitHub is a cloud-based hosting service for Git repositories that adds collaboration features like pull requests, issues, and Actions; Git can exist without GitHub, but GitHub requires Git.

2. What is the difference between git pull and git fetch?

beginner

git fetch downloads changes from the remote repository but does not merge them into your working branch, leaving your local branch unchanged. git pull is essentially git fetch followed by git merge, automatically integrating the remote changes into your current branch.

3. What is a branch in Git and why is it useful?

beginner

A branch is a lightweight, movable pointer to a specific commit that lets you work on features or fixes in isolation without affecting the main codebase. Branches enable parallel development, safer experimentation, and clean integration through merging or rebasing.

4. What is the difference between git merge and git rebase?

intermediate

git merge creates a new merge commit that combines two branch histories, preserving the full context of when branches diverged. git rebase replays commits from one branch on top of another, producing a linear history but rewriting commit SHAs, which can cause issues on shared branches.

5. What does git stash do and when would you use it?

beginner

git stash temporarily shelves uncommitted changes so you can switch branches or pull updates without committing incomplete work. You can later restore the changes with git stash pop or git stash apply.

6. Explain the Git staging area (index).

beginner

The staging area is an intermediate layer between the working directory and the repository where you selectively prepare changes before committing. This allows you to craft precise, logical commits by including only specific files or hunks from your working changes.

7. What is a detached HEAD state in Git?

intermediate

A detached HEAD occurs when HEAD points directly to a specific commit rather than to a named branch. Any commits made in this state are not on a branch and can be lost unless you create a new branch to retain them.

8. What is the difference between git reset and git revert?

intermediate

git reset moves the branch pointer backward to a previous commit, potentially discarding or unstaging commits — it rewrites history and is unsafe on shared branches. git revert creates a new commit that undoes the changes of a specific commit, preserving history and making it safe for shared/public branches.

9. What are the three modes of git reset (--soft, --mixed, --hard)?

intermediate

--soft resets the branch pointer but keeps changes staged; --mixed (the default) resets the pointer and unstages changes but keeps them in the working directory; --hard resets the pointer and discards all changes from both the staging area and working directory permanently.

10. What is a pull request (PR) and what is its purpose?

beginner

A pull request is a GitHub feature that proposes merging changes from one branch into another, enabling team members to review code, leave comments, request changes, and run CI checks before integration. It is the central collaboration mechanism in most team workflows.

11. What is git cherry-pick and when would you use it?

intermediate

git cherry-pick applies the changes from a specific commit onto the current branch without merging the entire source branch. It is useful for backporting a bug fix from main to a release branch or selectively bringing in an isolated change.

12. Explain the Gitflow branching strategy.

intermediate

Gitflow defines long-lived branches (main, develop) and short-lived supporting branches (feature/*, release/*, hotfix/*). Features branch from develop and merge back in; releases branch from develop and merge into both main and develop; hotfixes branch from main and merge into both main and develop.

13. What is a Git tag and how does it differ from a branch?

beginner

A tag is a static, named reference to a specific commit typically used to mark release points (e.g., v1.0.0), and it does not move as new commits are made. A branch is a dynamic pointer that advances automatically with each new commit.

14. What is git bisect and how does it work?

advanced

git bisect performs a binary search through commit history to identify the commit that introduced a bug. You mark a known good commit and a known bad commit, then Git checks out midpoints for you to test until the offending commit is isolated.

15. What is a Git submodule?

advanced

A submodule is a Git repository embedded inside another repository at a specific commit, allowing you to include external dependencies while keeping their histories separate. They must be explicitly initialized and updated, making them more complex to manage than package managers.

16. How does git rebase --interactive work and what can you do with it?

advanced

Interactive rebase (git rebase -i <commit>) opens an editor listing commits in a range, letting you reorder, squash, fixup, edit, drop, or rename individual commits before replaying them. It is commonly used to clean up a feature branch's history before merging.

17. What is the difference between a fast-forward merge and a three-way merge?

intermediate

A fast-forward merge simply moves the branch pointer forward when the target branch has not diverged — no merge commit is created. A three-way merge is used when histories have diverged; Git finds a common ancestor and combines changes, creating a new merge commit.

18. What is git reflog and when is it useful?

advanced

git reflog records every movement of HEAD (including resets, rebases, and checkouts) locally, even for commits no longer reachable from any branch. It acts as a safety net, letting you recover lost commits or undo destructive operations like a bad git reset --hard.

19. How do you resolve a merge conflict in Git?

intermediate

When a conflict occurs, Git marks conflicting sections in the affected files with conflict markers (<<<<<<<, =======, >>>>>>>); you manually edit the files to keep the desired changes, then stage the resolved files with git add and complete the merge with git commit or git merge --continue.

20. What is the difference between git clone --bare and a regular git clone?

advanced

A regular clone creates a working directory with a hidden .git folder, suitable for active development. A bare clone (--bare) contains only the repository data (what would normally be in .git) with no working directory, and is used for hosting a central remote repository on a server.

Practice these out loud with an AI interviewer that grills you and grades your answers.
Open the app — free to start

© RM Full Stack & AI Engineer · All interview questions · Roadmaps · Open the app