Skip to content
← All guides

What to do if an AI agent force-pushed main

Find the force push on GitHub, recover missing commits on a separate branch and keep your team’s current work while you review what to restore.

4 min read

Pause the agent and any job still pushing to the branch. On GitHub, open the repository’s Activity view, select main and filter for Force pushes. Find the event and save its before and after commit IDs. If the old commit still opens, create a separate recovery branch at the before ID. That preserves a reference to the missing history while the team reviews what belongs on today’s main. GitHub’s recovery procedure

Did the push reach GitHub?

Your colleague’s change disappears just after a coding agent finishes a task. Start by confirming the repository, remote and branch. A push to a fork, a rejected push and a change of local branch can all produce a confusing session summary. Look for the time, ref, authenticated account and before-and-after IDs in the repository’s activity. Use Compare changes where available. Write down one missing commit or a file change its author recognizes. GitHub repository activity

To work out whether the agent was involved, compare the remote event with the tool call and response in the relevant session. If the agent used your credentials, the host can record your account for its push. The account name alone cannot identify the process that used it. Ask collaborators to pause writes to the affected branch, keep any local copies and send their last known good commit IDs to the person coordinating recovery. Trace a shell command to an agent

Recover the earlier history

Evidence you still haveNext step
GitHub shows the force-push event and the previous commit opensOpen the tree at the before ID. Use the branch dropdown to create a new recovery branch there. You need write access. Check the recovered files and commit history.
Your clone still contains the old commitInspect it with git show --stat COMMIT_ID, substituting the verified ID. Give it a new branch with git branch ai-agent-recovery COMMIT_ID. Creating that reference leaves the branch you’re on and your working files in place.
You know the approximate time but have no IDCheck the affected clone’s reflog with git reflog show main. A clone that previously observed the remote branch may also have entries under origin/main. Look for the expected date, then inspect the candidate commit. Ask teammates to check their clones too.

A reflog records updates seen by that local repository. Entries expire, and a fresh clone may never have seen the earlier history. When neither GitHub nor a surviving clone has the old commit, look for a backup. Uncommitted edits belong to a different recovery path. Git reflog reference · Recover local files and uncommitted edits

What we checked. In a disposable repository on November 20, 2026, we created two different histories and left an uncommitted edit in the current working tree. We created a recovery branch at the verified earlier commit. Reading the file from that branch returned the teammate’s original text. The ID of main and the uncommitted file’s checksum stayed the same. This was a local Git check of one recovery step. GitHub documents the separate, hosted procedure above. Git branch reference

Review what should return to main

Assign one maintainer to compare the recovery branch with the current main. Ask the missing change’s author to confirm the intended files. Ask whoever landed work after the incident to identify changes that must survive. Prepare the agreed edits on a branch based on current main and open an ordinary pull request. Run the usual checks and have someone review the resulting diff. A second rewrite could discard work that arrived while you were investigating.

Before resuming the agent, protect main at the host. Check who can bypass the rule, whether force pushes are permitted and which reviews or status checks are required. Those settings apply when the server receives the push, including pushes made from another computer. Excellent’s Git guide explains how to inspect branch protection on GitHub or GitLab. Its free scan can help you find recorded agent actions on a supported Mac. GitHub protected branches · Excellent Git protection · Run the free scan

Related guides

View all