git rebase

Practice git rebase from memory. Rebase replays your commits on top of the target branch, producing a linear history. Caution note: rebasing rewrites loc

Rebase the current branch on top of main.

git rebase main

Rebase replays your commits on top of the target branch, producing a linear history. Caution note: rebasing rewrites local commit history; prefer merge for shared branches unless the team expects a rebase workflow.

Safety: Inspect first and avoid rewriting shared history unless the team expects it.

Start an interactive rebase to edit, squash, or reorder the last 3 commits.

git rebase -i HEAD~3

-i opens an editor listing recent commits. Caution note: interactive rebase rewrites local history by changing, squashing, dropping, or reordering commits; avoid it on shared branches without coordination.

Safety: Inspect first and avoid rewriting shared history unless the team expects it.

Abort an in-progress rebase and restore the previous branch state.

git rebase --abort

git rebase --abort returns the branch to its pre-rebase state using the saved ORIG_HEAD. Caution note: verify you are aborting the intended in-progress rebase before discarding conflict-resolution work.

Safety: Inspect first and avoid rewriting shared history unless the team expects it.

Continue the rebase after resolving a conflict.

git rebase --continue

After resolving a conflict and git add-ing the files, --continue resumes the rebase with the next commit. Caution note: verify the staged resolution before continuing because the rebased history will include it.

Safety: Inspect first and avoid rewriting shared history unless the team expects it.

Build the habit: GitDrill drills git rebase and the rest of the Git workflow until the safe first move is automatic. Try a Git drill.