bashintermediate

Git Rebase Workflow Example

Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.

bash
# 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~3

Use 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.