Git rebase: Clean commit history

Git rebase moves a sequence of commits on top of a base commit. Picture shows rebasing Feature branch on top of a Main branch.

Git Rebase

Rebasing Feature-branch on top of a Main-branch

1. Fetch latest changes from remote

git fetch origin

2. Checkout to Feature branch

git checkout feature

3. Rebase onto Main-branch

git rebase origin/main

4. Resolve conflicts manually and stage modified files

git add -u

5. Finally after resolving conflicts continue rebase

git rebase --continue

*Cancel rebase at any step with

git rebase --abort