A guide to maintaining a linear project history using git rebase and bringing in changes from main into feature_branch
git checkout main
git pull origin maingit checkout feature_branch
git rebase main# - Edit files to resolve conflicts
# - git add <file>
# - git rebase --continuegit push origin feature_branch --force-with-leaseWhy Rebase?
- Linear History: Eliminates "merge bubbles"; the log shows features developed in a clean sequence
- Debug-Friendly:
git bisectworks efficiently on a straight line of commits - Clean PRs: Reviews focus strictly on your changes, not merge noise
- Critical Rules
- Private Branches Only: Never rebase a branch shared with other developers
- It rewrites history and breaks their local copies
- Force with Lease: Always use
--force-with-leaseinstead of--forceto prevent overwriting unexpected remote changes - Conflict Resolution
- Rebasing resolves conflicts one commit at a time
- Git pauses at the conflicting commit
- Resolve the conflict in your editor
git add <file>thengit rebase --continue- Use
git rebase --abortto safely cancel and return to the original state - Pro Tip: Enable auto-stashing to handle uncommitted changes automatically
git config --global rebase.autoStash true