StoicBuilder

HandbookIX the CuriaRebase and merge

IXthe Curia, Work as a team

Rebase and merge

1 min readUpdated 28 November

In plain words

Merging joins two branches with a merge commit and keeps history as it happened, while rebasing replays your commits on top of the latest main, giving a straight history but new commit ids.

Where you see it

Your Harbor branch is 30 commits behind main. git merge origin/main adds one merge commit to your branch, while git rebase origin/main moves your commits so they start from today's main. GitHub's merge button offers a similar choice: Create a merge commit, Squash and merge, or Rebase and merge.

Terminalterminal
# a branch only you work on: rebase onto maingit fetch origingit rebase origin/maingit push --force-with-lease # a branch others have pulled: merge insteadgit merge origin/main
--force-with-lease refuses to push if the remote branch has commits you haven't fetched.

What goes wrong

  1. Rebasing a branch others are using

    Rebase rewrites commit ids. A teammate who pulled the old ones now has a diverged branch, and your force push can wipe out commits they pushed. Rebase only branches you alone work on.

  2. Pushing with plain --force

    Plain --force overwrites the remote branch whatever is on it. Use --force-with-lease, which stops if the remote has commits you haven't seen.

    git push --force
  3. Resolving the same conflict again and again

    A rebase replays each commit in turn, so one conflict can return at several of them. On a long branch a single merge may be less work, and turning on git rerere lets git reuse resolutions you've already made.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Update my feature branch with the latest main. If only I have worked on it, rebase onto origin/main and push with --force-with-lease; if anyone else has pulled it, merge origin/main instead. Never force-push to main, and show me git log --oneline --graph -15 afterwards.

Quick check

Sign in to earn +10 XP for it

You and a teammate both push to feat/team-billing. You rebase it onto main and force-push. What happens to your teammate?

Got a prompt that touches rebase and merge?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.