← Back to Git Course | Chapter 8: Best Practices | Lesson 5 of 6

Git Interview Questions

What is the difference between Git and GitHub?

Git is the version control software itself — it works entirely offline and doesn't require any server. GitHub is a company's hosting service built on top of Git, adding a web UI, pull requests, issue tracking, and a remote place to store repositories — you could use Git fully without ever touching GitHub.

Example: What is the difference between Git and GitHub?

bash
git init
# vs.
git remote add origin https://github.com/user/repo.git

What is the difference between merge and rebase?

A merge creates a new commit with two parents, preserving the exact shape of how both branches' histories actually happened, including every intermediate commit. A rebase replays your commits one by one onto a new base, producing a straight line with no merge commit — cleaner to read, but it rewrites commit hashes, which is unsafe on a branch others have already pulled.

Example: What is the difference between merge and rebase?

bash
git merge feature-x
# vs.
git rebase main

What does git stash do?

git stash snapshots your uncommitted changes (staged and unstaged) onto a stack and resets your working directory to match the last commit, giving you a clean slate to switch tasks without committing unfinished work — you bring the changes back later with git stash pop.

Example: What does git stash do?

bash
git stash
git stash pop

What is a detached HEAD state?

Checking out a commit hash or tag directly (instead of a branch name) puts HEAD in a "detached" state — you're on a specific commit rather than the tip of any branch, so any new commits you make there aren't attached to a branch and can be lost once you check out something else, unless you create a branch from that point first.

Example: What is a detached HEAD state?

bash
git checkout a1b2c3d

What is git cherry-pick?

git cherry-pick <hash> takes one specific commit from anywhere in the repository's history — often another branch — and replays it as a new commit on your current branch, useful for pulling in a single fix without merging that branch's other, unrelated commits.

Example: What is git cherry-pick?

bash
git cherry-pick a1b2c3d
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.