Claude Code tried to force push over main after a rebase

5 min read

Claude Code hit a rebase conflict, then sent git push --force origin main. HOL Guard paused it before it left the laptop: Allow just this once or Keep blocked.

Claude Code tried to force push over main after a rebase
On this page

You were in Claude Code. A rebase hit a conflict, Claude Code sorted it out locally, and then the push failed because your branch and origin/main no longer agreed. Its fix was one line: git push --force origin main. The reason it gave was "Force push the rebased branch so the remote matches local after the rebase conflict." Nobody asked you first.

If that runs, the remote main becomes a copy of your local main. Any commit a teammate pushed after your last fetch drops off the branch. Their pull request still says merged, and the work is no longer on main. The next person to pull gets your version of history.

HOL Guard paused the push before it left your machine. Two buttons came up on screen: Allow just this once, or Keep blocked. Until you click Allow, nothing has been sent to the remote.

HOL Guard Inbox: paused git push --force origin main from Claude Code, Allow just this once and Keep blocked

Local Inbox review when Claude Code queued git push --force origin main. The rule line reads "Git protection asks before Forced Git push."

Close-up of the command and the Allow just this once and Keep blocked buttons on the HOL Guard review card

Button labels on the live review card. Allow covers this one push only.

Keep blocked leaves the remote as it is. The receipt stays on your machine.

What does git push --force actually overwrite?

A normal push only adds commits on top of what the remote already has. If the remote has commits you don't, Git refuses. --force (or -f, or a + in front of the branch name) turns that check off: the remote branch is pointed at your local commit, whatever was there before.

So the loss depends on timing. If nobody else pushed since your last fetch, a force push after a rebase only replaces your own old commits. If someone did, their commits are no longer on the branch. Copies may still exist in their local clone or in a reflog, but someone has to notice first and know where to look.

Some repos block this at the host. GitHub branch protection can reject force pushes to main if the repo owner turned it on. Plenty of repos never do, and personal or early-stage projects almost never do.

Why the chat confirmation isn't enough

Claude Code wrote its own reason and sent the shell command. A rejected push right after a rebase is exactly when an agent reaches for --force, because it makes the error go away. Whether anyone else pushed in the meantime doesn't come into it.

A confirmation in the chat only happens if the agent decides to ask. Guard sits on the tool call itself. The pause happens because the command matched a rule. Claude Code can't click Allow for you, and if it tries to approve its own request from the shell, that's a separate Guard Extension (command.guard-self-protection).

What Guard maps

Built-in Git protection (command.git, v1.0.0, 43 rules). The operation in this post is Forced Git push (command.git.force-push), catalog default review, permission ID command.git.permission.force-push.

In our tests on Guard 3.59.0, git push --force origin main, git push -f origin main and git push origin +main all came back as review under command.git.force-push.

git push --force-with-lease is handled differently. It refuses to overwrite the remote if someone pushed since your last fetch, so it's the safer habit. Guard doesn't treat it as a force push: it falls under the plain Git push rule (command.git.push), which is off by default in the catalog.

A workspace can tighten force push to block. On Protect / Extensions, leave posture at Protected unless you have a reason to Watch. Watch will not stop the push.

Where to download Guard

Guard is free and open source. Download Guard Desktop from the installation page: macOS 13 or later on Apple Silicon, Windows x64, or Linux x86_64. Open the app and it walks you through setup. No terminal needed.

Prefer the terminal? The same page carries a one-command install you can copy instead. Either way, run hol-guard doctor afterward. It confirms the daemon is running, and the intercept layer is active, which is what makes the pause in this post happen.

How do I test it without pushing anything?

Install HOL Guard from the install page, then run:

hol-guard init

Then check the rule. command test and command explain don't run the command, create an approval, or write a receipt. You don't need a repo open.

hol-guard command test 'git push --force origin main'
hol-guard command explain 'git push --force origin main'

To see what a force push would change before you allow one, use the dry run. It is the catalog's safe variant and Guard doesn't pause it:

git push --force --dry-run origin main
git fetch origin && git log --oneline main..origin/main

The second line lists commits on the remote that your push would drop. If it prints anything, ask whose they are before you allow the push.

Out of scope

This post covers command.git.force-push. It doesn't cover:

  • git push --force-with-lease, which is matched by command.git.push (off by default) instead.
  • git reset --hard, which throws away local changes. That's its own operation, command.git.hard-reset, also review by default.
  • Deleting a repository on GitHub with gh repo delete, which belongs to command.github.
  • Force pushes made outside an agent, from your own terminal without Guard in the path.
  • An agent approving its own pending request: command.guard-self-protection.

After the Inbox lights up

Read the branch on the card. A force push to your own feature branch after a rebase is routine. A force push to main, master or a release branch deserves the main..origin/main check above.

If the remote has nothing you'd lose, choose Allow just this once. If not, Keep blocked and ask Claude Code to pull, rebase onto the new commits and push normally, or to push with --force-with-lease. The receipt stays local. Cloud sync is optional and doesn't carry the raw command.

What do people ask about AI agents and force push?

Can I get commits back after a force push?

Often, if you act quickly. The person who wrote them still has them in their local clone, and git reflog on any machine that had the old branch shows the previous commit. Hosts may also keep a record of the old commit. None of that is automatic, so it's easier to stop the push.

Is git push --force-with-lease safe for an agent to use?

Safer. It refuses to push if the remote branch moved since your last fetch, so it won't silently drop a teammate's commit. It can still overwrite commits you fetched but didn't look at.

How do I stop Claude Code from force pushing?

Install HOL Guard and keep Git protection (command.git) at Protected. When Claude Code sends git push --force, Guard pauses it in the Inbox until you choose Allow just this once or Keep blocked.

Does this work for Cursor or other coding agents?

The pause in this post was captured from Claude Code. The rule matches the command text whichever agent sent it, so hol-guard command test 'git push --force origin main' shows you the verdict without any agent involved.

Background: HOL Guard 3.0.

All articles

Keep exploring

The engineering desk continues across the ecosystem: security research on shipping agents safely, and plugins that put the standards to work.