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.
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.
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.
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.
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.
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.
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.
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.
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.
--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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
© RM Full Stack & AI Engineer · All interview questions · Roadmaps · Open the app