What are the 4 main Git states/areas in a typical workflow?
Working directory (your files), Staging area/Index (what will be committed), Local repository (your commit history), Remote repository (shared repo, e.g., origin on GitHub).
What is a commit in Git (conceptually)?
A commit is a snapshot of the project state (the staged content) plus metadata (author, message, parent commit(s)).
What is a branch in Git (conceptually)?
A branch is a movable pointer (reference) to a commit; it represents a line of development.
What is HEAD in Git?
HEAD points to the currently checked-out commit/branch—your current position in history.
Why is constructor injection preferred over field injection in many codebases (Git collaboration angle)?
Constructor injection makes dependencies explicit and encourages small, testable units—this leads to smaller, clearer changes and PRs that are easier to review.
What is a Pull Request (PR) in GitHub?
A request to merge changes from one branch into another, with discussion, review, and automated checks (CI) before integration.
What makes a PR ‘good’ and easy to review?
Small scope, clear description (what/why/how), tests included, minimal unrelated formatting changes, notes on edge cases and risks.
What should you focus on during code review?
Correctness, readability, maintainability, edge cases, performance hotspots, security concerns, and meaningful tests.
What is ‘branch protection’ in GitHub?
Rules that protect important branches (e.g., main): requiring PRs, passing CI checks, approvals, preventing force pushes, etc.
What is the difference between merge and rebase (high level)?
Merge combines histories (often creating a merge commit). Rebase rewrites commits to apply them on top of another base, producing a linear history.
When is merge a good choice?
When you want to preserve the context of how features were integrated, or when team policy prefers merge commits.
When is rebase a good choice?
Before opening/updating a PR to keep a clean linear history and resolve conflicts early—especially for local feature branches.
Why is rebasing shared branches risky?
Rebase rewrites commit history; teammates who pulled the old history will have conflicts and confusion unless coordinated.
What is a fast-forward merge?
A merge where the target branch pointer simply moves forward because it’s an ancestor of the source—no merge commit needed.
What is ‘squash merge’?
Merging a PR by combining all its commits into a single commit on the target branch, keeping main history clean.
Squash merge: pros and cons?
Pros: clean history, one commit per PR. Cons: loses intermediate commit details; harder to trace granular steps.
Merge commit: pros and cons?
Pros: preserves exact branch history and context. Cons: can make main history noisy.
Rebase-merge in GitHub: what is it?
GitHub can rebase the PR commits onto the target branch and then fast-forward, producing a linear history without a merge commit.
What is the difference between git fetch and git pull?
fetch downloads remote refs/commits without merging. pull = fetch + integrate (merge or rebase depending on configuration).
What does git pull --rebase do?
Fetches remote changes then rebases your local commits on top of the updated upstream branch to keep history linear.
What does git status tell you?
Current branch, staged changes, unstaged changes, untracked files, and next actions.
What does git diff show?
Line-by-line changes between working directory and index (or between other refs depending on flags).
Why is git add -p useful?
It lets you stage changes interactively (hunk-by-hunk), enabling focused commits and cleaner PRs.
What is a ‘clean commit’?
A commit that contains one logical change, with a clear message and minimal unrelated edits.