glossaryGit Rebase
A git operation that rewrites commit history by applying commits from one branch onto the tip of another, creating a linear history without merge commits.
explanation
Rebasing is one of two primary ways to integrate changes from one branch into another (the other being merging). When you rebase, git takes the commits from your current branch, temporarily sets them aside, fast-forwards to the target branch's tip, then reapplies each commit on top. The result is a linear history that reads as if each change was authored sequentially against the latest code. Interactive rebase (git rebase -i) is the more powerful form. It opens an editor where you can reorder, drop, squash, fixup, edit, or split commits. This is the primary tool for cleaning up a feature branch's history before merging — turning a series of WIP checkpoints into a coherent set of atomic commits. A critical rule of rebasing: never rebase commits that have been pushed to a shared branch. Rebasing creates new commit hashes, so anyone who has pulled the old version will experience duplicate commits and merge conflicts. The safe workflow is to rebase local work before pushing, and use merge or rebase + force-push only on branches you own exclusively.
examples
git rebase main # rebase current branch onto maingit rebase -i HEAD~5 # interactively rebase last 5 commitsgit rebase --abort # abort the rebase in progressgit rebase --continue # continue after resolving conflictsgit rebase --onto main feature-branch # rebase from feature-branch onto mainhow git-agent helps
git-agent produces clean, atomic commits from the start, so interactive rebasing for cleanup is rarely needed. When you do need to rebase, the conventional commit messages git-agent generates make the rebase todo list self-explanatory — each commit's purpose is clear at a glance.
brew install gitagenthq/brew/git-agentFAQ
What is the difference between rebase and merge?Why should I not rebase a shared branch?Does git-agent use rebase internally?