git rebase

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2020 Jan 9 14:31
Editor
Edited
Edited
2026 Feb 18 17:8

Enabled by AI agents as an alternative to merge

Conceptually similar to running cherry-pick multiple times
History becomes cleaner, but commits are lost and it's tedious to do per commit
Since this modifies history, avoid rebasing on master and instead rebase main before merging to master
In other words, enables fast-forward merge for features

VSCode interactive setup

git config --global core.editor "code --wait" git rebase -i main

Modifying multiple commit messages

  • amend e - edit commit
  • drop d - delete commit
  • squash s - combine commits
  • pick p - use commit
  • reword r - use and edit
  • fixup f - discard log and s
  • exec x - exec run command
git rebase -i HEAD~3

Moving base branch

  • Moves the branch divergence point to the latest commit of the target branch, rebasing current commits there
git rebase master

Updating to current time

If you've done git rebase -i, you should always follow it with git rebase --continue.
Rewind time, then fast-forward again
git rebase --continue

Canceling rebase

git rebase --abort git rebase --edit-todo

Merge conflict flow

git rebase --abort # revert git rebase --continue # it is like make new branch # i do git add . git commit -m blabla
 
 
 
 
 

Recommendations