- What is a Branch?
Imagine you’re writing a group project report.- You have the main version (final draft).
- You want to experiment with new ideas (e.g., add diagrams, try new sections).
- But you don’t want to mess up the main version until you’re sure.
That’s exactly what a branch is in Git: - It’s like creating a separate copy of your project to work on.
- You can make changes safely without disturbing the main branch.
- Why Do We Need Branches?
- Experiment Safely → Try new features without breaking the main code.
- Work in Parallel → Different team members can work on different features at the same time.
- Organized Workflow → Keep main branch stable, while feature branches hold new changes.
- Common Branches You’ll See
- main (or master) → The stable, production-ready version.
- feature branches → For new features (e.g., feature-login, feature-cart).
- bugfix branches → To fix issues without disturbing main code.
Basic Commands for Branching:
1. Create a new branch
git branch feature-1
This creates a branch but doesn’t switch to it yet
2. Switch to a branch
git checkout feature-1
3. See all branches
git branch
4. Delete a Branch
git branch -d branch-name-to-delete