WEEK 7 · LESSON 6 · TOPIC 2 OF 8 · How It Works

How It Works

Lesson progress

0% Complete

SECTION 1 OF 1

In this topic · 1 sections
  1. Overview

Overview

List the repository's branches with:

git branch

The current branch is marked with an asterisk.

Create a branch with:

git branch development

A newly created branch begins from the exact committed state of the branch you were on at creation time. If development is created while main is current, development initially points to the same project state as main.

Switch to the new branch with:

git checkout development

The working directory now reflects the files and committed state of development.

If you create a file, stage it, and commit it while on development, that commit belongs to development:

git add .
git commit -m "Add 3.txt on development"

When you switch back to main:

git checkout main

The branch-specific file may disappear from the working directory because main does not contain the development commit.

Git is not deleting the work. It is changing the visible working tree to match the branch you selected.

This branch isolation applies in both directions. Main can receive its own commit while development receives a different commit. Each branch then represents a different continuation of their previously shared history.