CodeBlanks Logo Icon CodeBlanks

What is a branch?

Learn how a branch tracks commits.

What is a branch?

A Git branch is a movable pointer to a specific commit in the commit history. When a new commit is created, the corresponding branch pointer advances to the new commit. This allows different lines of work to continue independently.

main
  |
  v
A -- B -- C

In this example, the main branch points to commit C.

The relationship between HEAD and a branch

HEAD identifies the branch or commit you are currently on in Git. Usually, HEAD points to the current branch, and that branch points to its latest commit. When you create a new commit, the branch pointer advances.

HEAD
  |
  v
main
  |
  v
A -- B -- C

In this example, HEAD points to the main branch, and main points to commit C.

Practice Display a branch pointer

Create a short output describing a Git branch position in commit history. Print that the main branch points to commit c3 and HEAD is on main.

Starter code

terminal
# Dal bilgisini yazdır
print("Branch: ")
print("Commit: ")
print("HEAD: ")

Sample solution

terminal
print("Branch: main")
print("Commit: c3")
print("HEAD: main")

Expected output

Branch: main
Commit: c3
HEAD: main

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the main purpose of a branch?

  • Changing commit messages
  • Resetting Git configuration
  • Pointing to a position in commit history Correct answer
  • Automatically deleting repository files

Explanation: A branch is a pointer that identifies a specific commit in the commit history.

2 The position a branch identifies

Question
main -> ____
Answer
main -> commit

Explanation: A branch points to a commit in the history, not to the working tree or staging area.

3 Parts of branch structure

Term Meaning
Branch Commit pointer
HEAD Identifies current position
Commit Recorded changes
main Common branch name

All lessons in Beginner