Skip to content
Versora

Manual

Branches and remotes

Merge, squash merge and rebase between branches

7 min read

On this page

There are three ways to bring the work from one branch into another:

  • Merge: combines the other branch's commits into the current one. When both have moved, git creates a merge commit with two parents.
  • Squash merge: brings all the other branch's changes in as a single commit on the current one, without linking the histories.
  • Rebase: redoes the current branch's commits on top of the other branch's tip. The history stays linear, but the redone commits get new IDs.

The three actions are in the menu of any branch (local or remote) and apply to the current branch. To combine two branches without checking one out first, drag one onto the other (see Dragging branches).

Merge another branch into the current one

Where to find it

With main checked out, in the feature/login branch's menu (LOCAL or REMOTE panel, or the label in the graph):

  • Merge feature/login into main
  • For a remote branch: Merge origin/feature/login into main
  • In a commit's menu, the submenu of each remote branch pointing to it has the same item.

Step by step

  1. Check out the branch that will receive the merge (for example, main).
  2. Right-click the branch that will go in (feature/login).
  3. Choose Merge feature/login into main.
  4. If conflict prediction finds a conflict, the Before merging dialog opens (see below).
  5. The bar shows "Merging feature/login…". Without a conflict, the merge finishes on its own, with git's default message.

What Versora does in git

bash
git merge --no-edit feature/login

--no-edit accepts git's default message ("Merge branch 'feature/login'") without opening an editor. If main has no commits that feature/login doesn't have, git just moves main forward (fast-forward).

How to undo

Ctrl+Z undoes "Merge feature/login": the current branch goes back to the commit before the merge. With the merge stopped midway by a conflict, Ctrl+Z doesn't undo the merge: to give up, use Abort. Once you finish the stopped merge (with Continue, through the commit box or with Finish the merge without hooks), Ctrl+Z undoes the whole merge, with the conflict resolutions, and takes the branch and the files back to the commit before the merge.

Local squash merge

Use it when the work branch's history doesn't matter ("wip" commits, typo fixes) and you want a clean commit on the destination.

Where to find it

  • The branch's menu: Squash merge feature/login into main…, right below the regular merge.
  • Also in a remote branch's menu and in the remote branches' submenu in the commit menu.

Step by step

  1. With main checked out, choose Squash merge feature/login into main….
  2. The Squash merge feature/login into main dialog explains: "The 4 commits from feature/login go into main as a single commit, with the message below (feature/login's history isn't linked to main's)."
  3. Review the Summary (it comes filled in with "Squash merge feature/login into main") and the Description (it comes with the list of the commits brought in, one per line, from oldest to newest).
  4. If you want to skip the commit hooks, check Skip hooks on the commit (--no-verify).
  5. Click Squash merge.
  6. If conflict prediction finds a conflict, the Before merging dialog opens.
  7. At the end, "Squash merged feature/login into main" appears.
OptionWhat it doesDefault
SummaryThe first line of the commit message."Squash merge feature/login into main"
DescriptionThe body of the message.one * title per commit brought in (without the merge commits)
Skip hooks on the commit (--no-verify)Doesn't run the pre-commit and commit-msg hooks on the squash commit.unchecked

What Versora does in git

bash
git merge --squash feature/login
git commit -q -F -          # the dialog's message, through standard input
# with the box checked: git commit -q -F - --no-verify

When it doesn't work the first time

  • Nothing to bring in: "Nothing to bring in: everything in feature/login is already in main." No commit is made.
  • Conflict: "The squash merge hit conflicts. Resolve the conflicted files and commit: the prepared message is already in the commit field." Resolve them in the conflict editor and commit through the usual commit box.
  • Commit rejected (hook, signing…): "The commit wasn't made, but the squash result is staged and the prepared message went to the commit field." Fix the cause and commit.

In those last two cases, the commit box shows "Prepared message from the squash merge of feature/login", with Use and a button to dismiss the message.

How to undo

Ctrl+Z undoes "Squash merge of feature/login" once the commit is made.

Rebase the current branch onto another

Rebase takes the commits that only the current branch has and reapplies them on top of the other branch's tip. It's the way to update a work branch with main without a merge commit.

Where to find it

With feature/login checked out, in the main branch's menu:

  • Rebase feature/login onto main
  • For a remote branch: Rebase feature/login onto origin/main
  • To choose commit by commit (reorder, combine, edit): Interactive rebase of feature/login onto main… (see History).

Step by step

  1. Check out the branch that will be redone (feature/login).
  2. In the base branch's menu (main), choose Rebase feature/login onto main.
  3. If conflict prediction finds a conflict, the Before rebasing dialog opens.
  4. The bar shows "Rebasing onto main…".

What Versora does in git

bash
git rebase main

Caution

Rebase changes the IDs of the redone commits. If the branch was already on the remote, the next push will have to be forced (see Force push). Don't rebase a branch other people use without agreeing on it first.

How to undo

Ctrl+Z undoes "Rebase onto main": the branch goes back to the previous commits. If the rebase stopped at a conflict and you finished it later (with Continue or Skip this commit in rebase until the end, or even from the terminal), the whole rebase goes into Ctrl+Z when it finishes, as if it had never stopped. If aborted, nothing goes in: the branch is already back to what it was.

Conflict prediction before merge and rebase

Before starting, Versora simulates the merge (or the rebase) in memory, without touching your files. If the simulation finds a conflict, the Before merging or Before rebasing dialog opens, with the Conflict predicted block: "Merge feature/login into main is expected to conflict in 2 files:" and the list of files.

  • Merge anyway (or Rebase anyway) goes ahead. The merge stops at the conflicts and the conflict editor helps you resolve them; the rebase stops at each commit that conflicts.
  • Back gives up without changing anything.

The prediction only takes into account the commits on both sides: uncommitted changes aren't counted. It needs git 2.38 or newer and can be turned off in Preferences › Checks › Conflict prediction › Before merging or rebasing. See Conflict prediction.

When the operation stops at a conflict

If the merge or the rebase stops at a conflict, the notice "The operation stopped because there are conflicts in 2 files." shows up with the guidance: "Click each file in the "Conflicted" section to resolve it in the conflict editor, then click Continue — or Abort to give up."

From the palette (Ctrl+P) there are also "Continue merge", "Abort merge" and, in a rebase, "Skip this commit in rebase". The conflict editor is in Conflicts.

While the operation is stopped, Ctrl+Z undoes the resolution steps (saving a file in the conflict editor, using one of the versions, staging a conflicted file, a discard), one at a time. When the operation finishes, those steps leave the undo history and the whole operation goes in: the next Ctrl+Z goes back to the state before the merge or the rebase. See Stopped merge, rebase, cherry-pick and revert.

Hooks that reject the merge or the rebase

  • A pre-merge-commit or commit-msg hook that rejects the merge commit leaves the merge in progress, with everything staged. The notice says "The pre-merge-commit hook refused the merge commit. The merge is still in progress, with everything staged." and offers Finish the merge without hooks.
  • A pre-rebase hook that rejects the rebase makes the notice offer Try without hooks.

See Skip hooks.

Caveats and messages

  • "You're on a detached HEAD: check out the branch that will receive the squash merge.": the squash merge needs a branch checked out.
  • "The commit message is empty.": the squash merge summary can't be left blank.
  • The merge and rebase items don't show up with a detached HEAD: check out a branch first.
  • Preferences › Checks › Conflict prediction: Warn when it would conflict (before merging or rebasing) and Predict conflicts in the background (marks branches with ⚠).
  • To see beforehand what a merge would bring in, use What enters main when merging feature/login in the branch's menu (see Inspection).

See also