What is a “detached HEAD” in Git?

What is a “detached HEAD” in Git?

a) A state where HEAD points to a commit instead of a branch
b) A corrupted branch
c) A repository without a HEAD
d) A branch without commits

Answer:

a) A state where HEAD points to a commit instead of a branch

Explanation:

A “detached HEAD” state in Git occurs when HEAD points directly to a commit rather than a branch. This can happen when you checkout a specific commit instead of a branch, meaning any new commits you make won’t be associated with a branch.

While in a detached HEAD state, you can still make changes, but they are not linked to a branch unless you explicitly create one.

Understanding the detached HEAD state is important for avoiding confusion when working with commits that are not linked to branches.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top