Git Internals Questions with Answers

34 practice questions on Git Internals (Git & DevOps) with answers and step-by-step solutions. Try 10 samples below, then practise all 34 free in the AptiNest app.

Sample questions

Question 1Easy

Git stores history as a

  1. Linear list of files
  2. Directed acyclic graph of commits
  3. Single big file
  4. Table of diffs only

Answer: B. Directed acyclic graph of commits

Explanation

Each commit points to its parents, so history forms a DAG.

Step-by-step solution

  1. Each commit points to its parents, so history forms a DAG.
  2. So the answer is: Directed acyclic graph of commits.

Why the other options are wrong

  • A. Branches and merges make it a graph.
  • C. Objects are in a database.
  • D. Git stores snapshots.

Question 2Easy

Where does Git store repository history on disk?

  1. In a file named history.txt kept at the top of the project folder
  2. In the system registry
  3. In the node_modules folder
  4. In the hidden .git directory

Answer: D. In the hidden .git directory

Explanation

The .git folder holds objects, refs, config and the index. Deleting it removes the repository.

Step-by-step solution

  1. Every repo has .git.
  2. It contains objects and refs.
  3. Deleting it loses history.

Why the other options are wrong

  • A. No such file.
  • B. Git does not use a registry.
  • C. Unrelated to Git.

Question 3Medium

A detached HEAD means

  1. HEAD points directly to a commit, not a branch
  2. The repository is corrupted
  3. The remote is missing
  4. HEAD is deleted

Answer: A. HEAD points directly to a commit, not a branch

Explanation

Commits made in this state can be lost unless a branch is created.

Step-by-step solution

  1. Commits made in this state can be lost unless a branch is created.
  2. So the answer is: HEAD points directly to a commit, not a branch.

Why the other options are wrong

  • B. The repository is fine.
  • C. Remotes are unrelated.
  • D. HEAD still exists.

Question 4Medium

git reset --soft HEAD~1

  1. Deletes the working files
  2. Moves the branch back but keeps changes staged
  3. Keeps changes unstaged
  4. Rebases the branch

Answer: B. Moves the branch back but keeps changes staged

Explanation

--soft moves only the branch pointer.

Step-by-step solution

  1. --soft moves only the branch pointer.
  2. So the answer is: Moves the branch back but keeps changes staged.

Why the other options are wrong

  • A. Files are kept.
  • C. Unstaged is --mixed.
  • D. It does not rebase.

Question 5Medium

Two files in a repo have exactly the same content. How many blob objects does Git store for them?

  1. Two
  2. Zero
  3. One
  4. Three

Answer: C. One

Explanation

Blobs are named by a hash of content, so identical content is stored once.

Step-by-step solution

  1. Hash of content is the id.
  2. Same content gives same id.
  3. Names live in tree objects.

Why the other options are wrong

  • A. That would duplicate content.
  • B. Content must be stored.
  • D. No extra copy.

Question 6Medium

In which sub-directory is an object with the id ab12cd... stored?

  1. .git/refs/ab12cd
  2. .git/ab12cd/
  3. .git/hooks/ab
  4. .git/objects/ab/ as the file 12cd...

Answer: D. .git/objects/ab/ as the file 12cd...

Explanation

Loose objects use the first two hex characters as a directory and the remainder as the filename.

Step-by-step solution

  1. Take the id.
  2. First two chars: folder.
  3. Rest: file name.

Why the other options are wrong

  • A. Refs hold branch pointers.
  • B. No such layout.
  • C. Hooks hold scripts.

Question 7Medium

The staging area is also called the

  1. Stash
  2. Index
  3. Reflog
  4. Worktree

Answer: B. Index

Explanation

The index holds the snapshot that the next commit will record.

Step-by-step solution

  1. The index holds the snapshot that the next commit will record.
  2. So the answer is: Index.

Why the other options are wrong

  • A. The stash stores shelved changes.
  • C. The reflog logs ref updates.
  • D. The worktree is the working directory.

Question 8Medium

A Git blob stores

  1. The commit message
  2. A directory listing
  3. A branch name
  4. The contents of a file, without its name

Answer: D. The contents of a file, without its name

Explanation

File names live in trees. A blob is just the content.

Step-by-step solution

  1. File names live in trees.
  2. A blob is just the content.
  3. So the answer is: The contents of a file, without its name.

Why the other options are wrong

  • A. That is the commit.
  • B. That is the tree.
  • C. That is a ref.

Question 9Hard

A fast-forward merge happens when

  1. Both branches have new commits
  2. There are conflicts
  3. The remote is ahead only
  4. The target branch has no new commits, so its pointer just moves forward

Answer: D. The target branch has no new commits, so its pointer just moves forward

Explanation

No new merge commit is needed when the history is linear.

Step-by-step solution

  1. No new merge commit is needed when the history is linear.
  2. So the answer is: The target branch has no new commits, so its pointer just moves forward.

Why the other options are wrong

  • A. That needs a merge commit.
  • B. Conflicts prevent fast-forward.
  • C. Remote is not required.

Question 10Hard

An annotated tag differs from a lightweight tag in that it

  1. Is just a branch
  2. Is a full object with tagger, date and message
  3. Cannot be pushed
  4. Is a copy of the repository

Answer: B. Is a full object with tagger, date and message

Explanation

Annotated tags store extra metadata; lightweight tags are plain refs.

Step-by-step solution

  1. Annotated tags store extra metadata;
  2. lightweight tags are plain refs.
  3. So the answer is: Is a full object with tagger, date and message.

Why the other options are wrong

  • A. Branches are separate.
  • C. Tags can be pushed.
  • D. It is not a copy.

Practise all 34 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Git & DevOps topics · All topics