Practical Git Rebase Use Cases

Git rebase is a powerful command for rewriting comit history. Below are two common scenarios where it proves especially useful: applying one branhc's commits onto another and removing or altering specific commits.

Bringing Changes from One Branch into Another

Suppose you have two branches: main and feature-x. Both have diverged with shared and unique commits. You want to apply the commits that exist only on main onto feature-x. The following steps accomplish that:

  1. Switch to main: ``` git switch main
  2. Rebase the current branch (main) interactively onto feature-x. The -i flag lets you review each commit individually: ``` git rebase -i feature-x
  3. During the rebase you may encounter merge conflicts. Resolve them as they appear, then continue the rebase with git rebase --continue. After all conflicts are resolved, main now has its unique commits placed on top of feature-x. The branch pointer remains on main.
  4. Switch back to feature-x: ``` git switch feature-x
  5. Finally, merge main into feature-x. This is typically a fast‑forward merge because main is now a direct descendant of feature-x: ``` git merge main
    
    

With feature-x up to date, you can push it to the remote.

Deleting or Editing a Specific Commmit

Consider a branch with commits alpha, beta, gamma, delta, epsilon, zeta. The commit delta is problematic and you want to remove it entirely. Use interactive rebase:

git rebase -i gamma

This command opens an editor listing the commits from gamma onwards (i.e., delta, epsilon, zeta). The instructions in the editor show:

# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

To delete delta, change its line from pick to drop (or simply delete the line). Save and exit the editor. Git will replay the remaining commits, effectively removing delta. After the rebase, the branch contains only alpha, beta, gamma, epsilon, zeta.

You can also use edit or reword to modify commit content or messages, respectively.

Tags: Git rebase interactive rebase Branch Management commit history

Posted on Fri, 07 Aug 2026 16:47:01 +0000 by VnVision