Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Branching, Merging, and Resolving ConflictsLesson 2.1

Understanding Branches in Git

git branch, HEAD pointer, branch concept, main branch, feature branches, branch listing

Understanding Branches in Git

A branch in Git is a lightweight movable pointer to a commit. When you create a branch, Git simply creates a new pointer — it does not copy any files. This makes branching in Git extremely fast and cheap compared to other version control systems.

DiagramGit Branch as a Pointer

IMAGE PROMPT (replace this block with your generated image):

Flat commit-graph diagram on white background. Title: How Git Branches Work. Horizontal chain of five commit circles (C1 → C2 → C3 → C4 → C5) connected by right arrows. Each circle contains a short hash (a1b, c2d, e3f, g4h, i5j). Above C5: a green tag badge labeled main with a down arrow pointing to C5. Branching off C3: a diagonal line going up-right to two more commits (B1 → B2). Above B2: a #3A5EFF-filled badge labeled feature/login with a down arrow. Above B2 also: a yellow star badge labeled HEAD showing the current position. Small legend box bottom-right: circle = commit, colored badge = branch pointer, star = HEAD. Annotation: Branches are just lightweight pointers — not copies of files. Brand color #3A5EFF for feature branch badge. White background, flat style.

The HEAD Pointer

HEAD is a special pointer that tells Git which branch you are currently on. When you commit, the current branch pointer moves forward to the new commit, and HEAD follows it. You can think of HEAD as your current position in the repository.

Listing Branches

Run git branch to see all local branches. The current branch is marked with an asterisk. To see remote branches as well, use git branch -a.

The Default Branch

When you initialize a repository, Git creates a default branch. In modern Git installations, this is named main. Older repositories may use master. You can rename it at any time:

git branch -m master main

Professional teams protect the main branch by requiring pull requests for all changes. Direct commits to main are typically blocked in collaborative projects.

Why Branch?

Branching lets multiple developers work simultaneously without interfering with each other. Each feature, bug fix, or experiment gets its own branch. Only when work is complete and reviewed is it merged into the main branch, keeping it stable at all times.

Up next

Creating and Switching Branches

Sign in to track progress