Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
# Update main branch
git checkout main
git pull origin main
# Rebase feature branch onto latest main
git checkout feature/my-feature
git rebase main
# If conflicts arise during rebase:
# 1. Fix conflicts in the files
# 2. Stage the resolved files
git add .
# 3. Continue the rebase
git rebase --continue
# To abort rebase and return to original state
git rebase --abort
# After successful rebase, force push (feature branch only)
git push --force-with-lease origin feature/my-feature
# Rebase last 3 commits onto main
git rebase --onto main HEAD~3Use Cases
- Keeping feature branches linear with main
- Cleaning up commit history before merging
- Avoiding merge commits in pull requests
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.
Git Stash Usage Examples
Save, list, apply, and manage uncommitted changes with git stash for quick context switching.
Git Interactive Rebase Guide
Interactive rebase to reorder, edit, drop, and squash commits for a clean Git history.