Lesson 3 — Git & GitHub Journey

Branching in Git
This is one of the MOST important Git concepts.
Branches allow developers to:
work safely
build features independently
avoid breaking main code
collaborate in teams
What is a Branch?
Think:
main branch = production code
New feature?
Create separate branch:
feature/login
Work there safely.
Visual Understanding
main
└── feature/login
Both branches can evolve independently.
1. Check Current Branch
Run:
git branch
You’ll see:
* main || * master
"*" star means current branch.
2. Create New Branch
git branch feature/login
Now check:
git branch
Output:
* main
feature-login
Branch exists but not switched yet.
3. Switch Branch
git switch feature-login
Now:
* feature-login
main
You are inside new branch.
Shortcut Command
Create + switch together:
git switch -c feature-payment
Very commonly used.
4. Make Changes in Branch
Inside feature-login:
echo "Login feature" >> notes.txt
Commit it:
git add .
git commit -m "add login feature"
Important Understanding
That commit exists ONLY in:
feature-login
Not in:
main
5. Switch Back to Main
git switch main
Now open file.
You’ll notice:
login feature line disappeared
Why?
Because commit belongs to another branch.
This is Git magic.
6. Merge Branch
Bring feature into main:
git merge feature-login
Now feature becomes part of main.
Visual After Merge
main
└── feature-login
↓
merged
7. Delete Branch
After merge:
git branch -d feature-login
Keeps repository clean.
Real Industry Workflow
main
├── feature/auth
├── feature/payment
├── bugfix/header
└── hotfix/api
Every developer works separately.
8. Merge Conflicts (IMPORTANT)
Conflict happens when:
- two branches modify same line
Example:
main:
Hello World
feature:
Hello Git
Git cannot decide automatically.
Conflict Example
Git shows:
<<<<<<< HEAD
Hello World
=======
Hello Git
>>>>>>> feature-login
You manually choose final version.
Then:
git add .
git commit
Conflict resolved.
Important Branch Commands
git branch
git switch
git switch -c
git merge
git branch -d



