Rebase
What is git rebase (in plain English)?
Rebase takes the commits on your current branch and replays them on top of another commit (often the latest main
).
This creates a clean, linear history (no merge commits) as if you had started your work from that newer point.
-
Merge: combines histories as they happened, preserving branches and creating a merge commit.
-
Rebase: rewrites history to look linear by moving your branch’s commits on top of a new base.
When to use:
-
Before opening a PR, to clean up/squash commits and sync with
main
. -
To remove accidental commits, fixup messages, or reorder small changes.
Safety note: Rebase rewrites commit IDs. It’s safe for local branches or branches only you own. If you’ve already pushed, use --force-with-lease
when pushing, and coordinate with collaborators.
Make Git use Nano (not Vim)
One‑time for this PowerShell session
Make Nano the default (all repos)
Alternatives if needed:
Short path (no spaces):
C:\Progra~1\Git\usr\bin\nano.exe -w
If
nano
is in PATH: set justnano -w
Interactive Rebase (Nano) — Quick How‑To
-
Start:
git rebase -i HEAD~N
Replace N with how many recent commits you want to edit (e.g.,
3
). -
In Nano, you’ll see lines like:
-
Change actions at the start of each line (use arrow keys to move cursor):
-
pick
— keep as‑is -
reword
— change commit message -
edit
— pause to amend content -
squash
— combine with previous, keep messages -
fixup
— combine with previous, discard this message -
drop
— remove this commit
-
-
Save & exit Nano: Ctrl+O, Enter, then Ctrl+X.
-
If you used
squash
/fixup
, Git opens another Nano window to edit the final message. Save & exit again.
If conflicts appear:
Common Workflows
A) Clean up duplicate commits (your case)
B) Update your feature branch to the latest main
C) Edit a commit’s content from a few commits ago
D) Change a commit message only
E) Drop an accidental commit
F) Autosquash “fixup!” commits
Pushing after a rebase (history changed)
Safer than
--force
; refuses to overwrite unexpected remote changes.
Quick Troubleshooting
-
“In the middle of a rebase”
-
Editor error with spaces in path
Use quotes when setting the editor: -
Confirm Nano works
No comments to display
No comments to display