Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn What is a Branch? | Branching Out: Exploring New Ideas Safely
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Git and GitHub for Absolute Dummies

bookWhat is a Branch?

Imagine you are writing a story. You have your main plot, but you want to try writing an alternate ending without changing what you already have. In Git, a branch works just like this: it creates a parallel timeline for your project. You can experiment, make changes, or even rewrite parts of your projectβ€”all without touching the main version. Think of each branch as a separate path the story could take, letting you explore different ideas side by side.

# Create a new branch called 'new-idea'
git branch new-idea

When you create a branch, Git makes a snapshot of your project at that moment. This new branch starts exactly where you are, with all your files and history. You are free to make changes in this branch, and nothing in your main project will be affected.

Step-by-step: What happens when you create a branch

  1. Git copies the current state of your project;
  2. It creates a new pointer (the branch) to this snapshot;
  3. You can switch to the new branch to start working;
  4. Any changes you make stay in this branch only;
  5. Your main project (the main branch) remains unchanged.

This is why branching is safe: you can try out new features, fix bugs, or rewrite sections, all without the risk of breaking your main work. If your experiment works out, you can later bring those changes back; if not, your original project remains untouched.

# Switch to your new branch to start working there
git checkout new-idea

1. What is a branch most like?

2. Why use branches?

question mark

What is a branch most like?

Select the correct answer

question mark

Why use branches?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookWhat is a Branch?

Swipe to show menu

Imagine you are writing a story. You have your main plot, but you want to try writing an alternate ending without changing what you already have. In Git, a branch works just like this: it creates a parallel timeline for your project. You can experiment, make changes, or even rewrite parts of your projectβ€”all without touching the main version. Think of each branch as a separate path the story could take, letting you explore different ideas side by side.

# Create a new branch called 'new-idea'
git branch new-idea

When you create a branch, Git makes a snapshot of your project at that moment. This new branch starts exactly where you are, with all your files and history. You are free to make changes in this branch, and nothing in your main project will be affected.

Step-by-step: What happens when you create a branch

  1. Git copies the current state of your project;
  2. It creates a new pointer (the branch) to this snapshot;
  3. You can switch to the new branch to start working;
  4. Any changes you make stay in this branch only;
  5. Your main project (the main branch) remains unchanged.

This is why branching is safe: you can try out new features, fix bugs, or rewrite sections, all without the risk of breaking your main work. If your experiment works out, you can later bring those changes back; if not, your original project remains untouched.

# Switch to your new branch to start working there
git checkout new-idea

1. What is a branch most like?

2. Why use branches?

question mark

What is a branch most like?

Select the correct answer

question mark

Why use branches?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1
some-alt