What 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
- Git copies the current state of your project;
- It creates a new pointer (the branch) to this snapshot;
- You can switch to the new branch to start working;
- Any changes you make stay in this branch only;
- Your main project (the
mainbranch) 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?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 8.33
What 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
- Git copies the current state of your project;
- It creates a new pointer (the branch) to this snapshot;
- You can switch to the new branch to start working;
- Any changes you make stay in this branch only;
- Your main project (the
mainbranch) 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?
Thanks for your feedback!