Git

Junior Questions

Junior
1

How do you write good commit messages?

Format:

Example:

Conventional Commits types:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation
  • style: Formatting (no code change)
  • refactor: Code restructuring
  • test: Adding tests
  • chore: Maintenance

What problems does this solve?

  • Ensures permanent repository history remains easily traversable, highly descriptive, and fundamentally understandable for future engineers.
Junior
2

What are the three states/areas in Git?

  • Working Directory: Your actual files
  • Staging Area (Index): Changes marked for next commit
  • Repository: Committed history

What problems does this solve?

  • Explains the exact geographical mechanics of the working directory, the staging index, and the permanent repository history.
Junior
3

What is .gitignore?

A file specifying patterns for files/directories Git should ignore.

Note: Files already tracked aren't affected. Use git rm --cached <file> to untrack.

What problems does this solve?

  • Prevents sensitive environment variables, massive dependencies, and compiled build outputs from accidentally polluting the repository.
Junior
4

What is Git and how is it different from GitHub?

  • Git: A distributed version control system that tracks changes in source code.
  • GitHub/GitLab/Bitbucket: Hosting platforms for Git repositories with additional features (PRs, issues, CI/CD).

Key concepts:

  • Repository: Project folder tracked by Git
  • Commit: Snapshot of changes
  • Branch: Independent line of development
  • Remote: Server-hosted copy of the repository

What problems does this solve?

  • Clarifies the absolute foundational distinction between the local version control engine and the external cloud hosting infrastructure.
Junior
5

What is HEAD in Git?

A pointer to the current commit/branch you're on.

What problems does this solve?

  • Explains the symbolic pointer that fundamentally dictates exactly what branch or specific commit the working directory is currently observing.
Junior
6

What is a Pull Request (PR) / Merge Request (MR)?

A request to merge changes from one branch into another with code review.

PR workflow:

  1. Create feature branch
  2. Push commits
  3. Open PR on GitHub/GitLab
  4. Code review + discussions
  5. Address feedback
  6. Approve and merge
  7. Delete feature branch

Best practices:

  • Small, focused PRs
  • Descriptive titles and descriptions
  • Link to issues/tickets
  • Include tests

What problems does this solve?

  • Explains the fundamental asynchronous peer-review gateway that protects the primary codebase from unverified or destructive code.
Junior
7

What is a fork workflow?

Workflow for contributing to repositories you don't own.

What problems does this solve?

  • Exposes the decentralized open-source collaboration model of copying a repository, pushing changes locally, and submitting up-stream PRs.
Junior
8

What is git log and useful options?

What problems does this solve?

  • Explains how to visually traverse, filter, and audit massive project histories using explicit graph topography.
Junior
9

What is git remote?

Manage connections to remote repositories.

What problems does this solve?

  • Explains the explicit DNS pointers that connect a local offline repository to various upstream cloud endpoints.
Junior
10

What is git stash?

Temporarily saves uncommitted changes without committing.

Use case: Switch branches without committing incomplete work.

What problems does this solve?

  • Provides a clean mechanism to explicitly vault uncommitted, work-in-progress code temporarily to urgently switch branches.
Junior
11

What is git tag?

Mark specific commits (usually releases).

What problems does this solve?

  • Creates strictly immutable, human-readable semantic versioning pointers anchored to incredibly specific release commits.
Junior
12

What is the difference between git fetch and git pull?

  • git fetch: Downloads changes from remote but doesn't merge them. Safe to run anytime.
  • git pull: Downloads AND merges changes (git fetch + git merge).

Best practice: Use fetch first to review changes, then merge/rebase manually.

What problems does this solve?

  • Highlights the critical difference between safely downloading remote updates versus aggressively merging them directly into the current branch.

Mid-Level Questions

Mid
13

How do you clean up a repository?

What problems does this solve?

  • Demonstrates how to aggressively purge untracked files, orphaned branches, and dangling garbage to drastically reduce repository bloat.
Mid
14

How do you undo changes in Git?

Discard unstaged changes:

Unstage files:

Undo commits:

What problems does this solve?

  • Demonstrates mastery over retrieving lost work, un-staging accidents, or nuking local uncommitted mistakes entirely.
Mid
15

What is a bare repository?

A repository without a working directory (only .git contents).

Use case: Central/remote repositories (e.g., what GitHub hosts).

What problems does this solve?

  • Explains the architecture of central remote servers, which contain zero working files and exist purely to accept and store pushed commits.
Mid
16

What is a merge conflict and how do you resolve it?

Occurs when Git can't automatically merge changes (same lines modified differently).

Tools: VS Code, IntelliJ, git mergetool

What problems does this solve?

  • Demonstrates the ability to manually untangle overlapping code modifications when automatic deterministic merging fails.
Mid
17

What is git blame?

Shows who last modified each line of a file.

What problems does this solve?

  • Provides forensic accountability by explicitly revealing the exact author and historical commit hash for every single line of a file.
Mid
18

What is git cherry-pick?

Apply a specific commit from another branch to your current branch.

Use cases:

  • Backport a bug fix to an older release
  • Grab a specific feature without merging entire branch

What problems does this solve?

  • Surgically extracts one specific, highly isolated commit from a completely different branch and duplicates it onto the current timeline.

Senior Questions

Senior
19

How do you rewrite commit history?

Amend last commit:

Interactive rebase: Edit multiple commits

⚠️ Never rewrite history on public branches.

What problems does this solve?

  • Demonstrates raw power-user capability to retroactively squash, edit, or reorder local commits before pushing cleanly to a public remote.
Senior
20

What are signed commits?

Cryptographically verify commit authorship using GPG.

Benefit: Proves commits are from who they claim to be.

What problems does this solve?

  • Uses cryptographic GPG signatures to categorically prove that a specific commit was authored by a specific, verified human.
Senior
21

What is Git Flow?

A branching model with structured branch types:

Branches:

  • main: Production-ready code
  • develop: Integration branch
  • feature/*: New features
  • release/*: Prepare releases
  • hotfix/*: Emergency fixes

Criticism: Too complex for many projects, slows deployment.

What problems does this solve?

  • Evaluates familiarity with strict, legacy release-branching methodologies commonly used in large, slow-moving enterprise environments.
Senior
22

What is Trunk-Based Development?

All developers commit to a single branch (main/trunk) with short-lived feature branches.

Practices:

  • Small, frequent commits
  • Feature flags for incomplete work
  • Branch lifespan < 2 days
  • Fast CI/CD pipeline

Preferred for: Continuous deployment, smaller teams.

What problems does this solve?

  • Highlights the modern, rapid-iteration continuous integration methodology of aggressively merging small changes directly into main.
Senior
23

What is a Git hook?

Scripts that run automatically on Git events.

Client-side hooks (.git/hooks/):

  • pre-commit: Before commit (linting, tests)
  • commit-msg: Validate commit message
  • pre-push: Before push (run tests)

Server-side hooks:

  • pre-receive: Before accepting push
  • post-receive: After accepting push (deploy)

Tools: Husky, lint-staged (easier hook management)

What problems does this solve?

  • Empowers teams to strictly enforce code formatting, linting, or test execution automatically just before a commit or push occurs.
Senior
24

What is a Git submodule?

Include another Git repository as a subdirectory.

Use cases: Shared libraries, monorepo components.

Downsides: Complex, easy to get out of sync. Consider npm packages instead.

What problems does this solve?

  • Allows massive monorepos to securely embed entire separate Git repositories completely inside a specific sub-directory.
Senior
25

What is git bisect?

Binary search to find the commit that introduced a bug.

What problems does this solve?

  • Utilizes a powerful binary search algorithm to deterministically hunt down the exact historical commit that introduced a subtle bug.
Senior
26

What is git reflog?

Records all HEAD movements (commits, checkouts, resets). Your safety net.

Use case: Recover from accidental git reset --hard or deleted branch.

What problems does this solve?

  • Acts as the ultimate safety net, allowing recovery of "deleted" commits or branches that have been orphaned from the chronological log.
Senior
27

What is git worktree?

Manage multiple working directories from one repository.

Use case: Work on multiple branches simultaneously without stashing.

What problems does this solve?

  • Enables checking out completely different branches simultaneously in separate physical directories without ever touching the stash.
Senior
28

What is the difference between git merge and git rebase?

Both integrate changes from one branch into another.

Merge: Creates a merge commit, preserves branch history.

Rebase: Moves commits to the tip of the base branch, linear history.

Rule: Never rebase public/shared branches.

What problems does this solve?

  • Evaluates the architectural tradeoff between preserving exact historical merge commits versus maintaining a perfectly linear, sequential history.
Senior
29

What is the difference between git reset and git revert?

CommandActionHistoryUse when
resetMoves HEAD backwardRewrites historyLocal/private branches
revertCreates undo commitPreserves historyPublic/shared branches

What problems does this solve?

  • Crucially distinguishes between aggressively erasing local commits versus safely appending anti-commits to a public history branch.
Senior
30

What is the difference between ~ and ^?

Both navigate commit ancestry:

  • ~ (tilde): Linear ancestry (first parent)
  • ^ (caret): Specific parent (for merge commits)

What problems does this solve?

  • Clarifies the obscure but critical syntactical difference between horizontal branch traversal and vertical commit traversal.