Useful Git
Git rebase
git rebase flow is basically a cleaner alterrnative to merge-based workflows. instead of creating messy merge commits, you "replay" your work on top of the lastest branch.
🔁 The idea (simple)
You have:
main: A --- B --- C
feature: D --- E
After rebbase:
main: A --- B --- C
feature: D' --- E'
Your commits (D,E) are rewritten on top of the lastest main.
🚀 Basic Rebase Flow
1. Create a feature branch
git checkout main
git pull origin main
git checkout -b feature/login
2. Work and commit
git add .
git commit -m "add login form"
3. Rebase with latest main (IMPORTANT STEP)
Before pushing or opening PR:
git checkout main
git pull origin main
git checkout feature/login
git rebase main
4. Fix conflicts (if any)
If Git stops:
# fix files manually
git add .
git rebase --continue
5. Push (force required ⚠️)
Because history changed:
git push origin feature/login --force
👉 Use --force-with-lease (safer):
git push --force-with-lease
🔀 Rebase vs Merge (real difference)
Merge:
git merge main
- Keeps history
- Adds merge commit ❌ (messy)
Rebase:
git rebase main
- Clean history
- Looks like linear timeline
🧠 Team Rebase Flow (clean workflow)
- Always branch from main
- Before PR → rebase on latest main
- Keep commits clean (optional: squash)
- Push with --force-with-lease
- Merge to main (usually fast-forward or squash)