Skip to content

Instantly share code, notes, and snippets.

@kashifulhaque
Created February 3, 2026 12:50
Show Gist options
  • Select an option

  • Save kashifulhaque/9ab7d777277425b6c9bf6f416424bd74 to your computer and use it in GitHub Desktop.

Select an option

Save kashifulhaque/9ab7d777277425b6c9bf6f416424bd74 to your computer and use it in GitHub Desktop.
The Clean Git Rebase Workflow

A guide to maintaining a linear project history using git rebase and bringing in changes from main into feature_branch

1. Update local main

git checkout main
git pull origin main

2. Rebase feature branch

git checkout feature_branch
git rebase main

3. Handle Conflicts (if any)

# - Edit files to resolve conflicts
# - git add <file>
# - git rebase --continue

4. Update Remote

git push origin feature_branch --force-with-lease

Why Rebase?

  • Linear History: Eliminates "merge bubbles"; the log shows features developed in a clean sequence
  • Debug-Friendly: git bisect works 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-lease instead of --force to 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> then git rebase --continue
    • Use git rebase --abort to safely cancel and return to the original state
    • Pro Tip: Enable auto-stashing to handle uncommitted changes automatically
      • git config --global rebase.autoStash true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment