Skip to content
Versora

Manual

Branches and remotes

Force push

3 min read

On this page

After rewriting commits that were already on the remote (rebase, amend, editing a message, squashing or dropping commits), the regular push is rejected: the server has commits your branch no longer has. A force push replaces the server's branch with yours.

In Versora, force push is always protected. If someone sent something to the branch after your last fetch, or if the fetch brought commits you haven't integrated into the local branch yet, the push is rejected instead of erasing that person's work.

Where to find it

  • The repository bar: the arrow next to Push (Push options) › Force push….
  • The current branch's menu: Force push….
  • Another local branch's menu: Force push… (sends that branch, without checkout).
  • Palette (Ctrl+P): "Force push…" (detail: "Overwrites the remote branch (--force-with-lease), with confirmation").

Step by step

  1. Rewrite the branch (for example, with a rebase onto main).
  2. Choose Force push….
  3. The Force push dialog asks: "Overwrite origin/feature/login with your local feature/login? Uses --force-with-lease: fails if the remote has commits you haven't fetched yet."
  4. Click Force push. If you check Don't ask again, the next times won't have this confirmation.
  5. The push checks run as in a regular push. A force push to a protected branch shows up as a danger (see Protected branches).
  6. At the end, "Pushed feature/login to origin/feature/login" shows up.
OptionWhat it doesDefault
Don't ask againTurns the confirmation off. The notice "Force push won't ask for confirmation anymore. You can turn it back on in Preferences › Operations." shows up with Open preferences.unchecked

What Versora does in git

bash
git push --force-with-lease --force-if-includes
# branch not checked out:
git push --force-with-lease --force-if-includes origin feature/a
  • --force-with-lease: only overwrites if the branch on the server is still where your origin/feature/login says it is.
  • --force-if-includes: also refuses when a fetch (including the automatic one) brought commits from the server that never went through your local branch. Without it, the lease would pass and those commits would be lost. It requires git 2.30 or newer; on an older git, only --force-with-lease is used and the git version warning bar warns you.

The protection stays on even with "Don't ask again": the option only removes the question.

How to undo

Ctrl+Z doesn't undo a force push: what changed was the server. If you overwrote something by mistake and still have the old commit (in the reflog, for example), create a branch on it and send it again (see Inspection for the reflog).

Caution

Force pushing a branch other people use forces all of them to redo their local work. Prefer forcing only your own work branches and talk to the team before forcing a shared branch.

Caveats and messages

  • A rejection by lease ("stale info" or "rejected" in git's output): someone sent commits to the branch. Pull (or rebase onto the remote branch) and force again.
  • "Push isn't available in detached HEAD.": check out a branch.
  • Protected branch: the checks dialog shows the Force push to a protected branch block, for example "You're about to overwrite main, which is protected on GitLab. This rewrites history that other people have already pulled." If the server doesn't accept force pushes on that branch, the block warns "GitLab doesn't allow force pushes to this branch: the push will likely be rejected."
  • A branch without an upstream: force push behaves like publishing a new branch (the Publish branch dialog).
  • Preferences › Operations › Pull, checkout and push › Force push › Confirm before force pushing (on by default). The hint explains: "Force push stays protected (--force-with-lease and --force-if-includes); this option only decides whether the app asks first."
  • The branch stack has its own force push, in a single confirmation (see Pushing the stack).

See also