#TIL 1 - Git Rebase Interactive | ProductsWay

#TIL 1 - Git Rebase Interactive

Aug 11, 2020 · Dung Huynh

What

Use git rebase -i to squash, reorder, reword, or drop commits from your local branch before you push.

Why

Reviewers see one commit per logical change when you squash related work together. Interactive rebase rewrites local commit IDs. Use it freely on an unpublished branch, but coordinate before rewriting a shared branch. If you already pushed the branch, update it with git push --force-with-lease rather than --force so you do not overwrite someone else's new commits.

How

git rebase -i HEAD~N

Replace N with the number of commits to edit. In the editor:

  • squash / s: combine with previous commit
  • drop / d: remove commit
  • reword / r: edit commit message
  • pick / p: keep commit as-is