Loading lessons...
Git Branches
Git Branches
A branch is a separate line of development. Branches let you work on new features without messing up the main version of your project.
Why branches?
- Try new ideas safely.
- Work on a feature while your team keeps the main branch stable.
- Fix bugs without touching new features in progress.
- Merge work back together when it is ready.
The default branch
When you create a repository, Git creates a default branch named main (older projects may call it master). This is usually the stable, production ready version of your project.
List branches
git branch
This lists all local branches. The branch you are on is marked with a * and highlighted.
Create a branch
git branch feature-login
This creates a new branch called feature-login, but it does not switch to it yet.
The big idea
Branches are just movable pointers to commits. Creating a branch is instant and cheap, so use them freely.
TL;DR
- A branch is a separate line of development.
- The default branch is usually called main.
git branchlists branches.git branch namecreates a new branch.