forkguarddocs

forkguard pr

Clean the repo on a new branch and open a pull request, so GitHub gets fixed too.

On this page

#Name

forkguard pr cleans a repo on a new branch, pushes it and opens a pull request, so GitHub is fixed too and not just your laptop.

forkguard pr - clean a repository and open a pull request

#Synopsis

forkguard pr
forkguard pr path/to/project
forkguard pr --upstream
forkguard pr [folder] [--upstream]

#Requirements

  • The folder is a git repo whose origin is on GitHub.
  • No uncommitted changes to tracked files. Commit or stash them first, so your work never mixes into the fix. (Untracked files are fine.)
  • You are on a branch, not in a detached HEAD.
  • A way to talk to GitHub: the GitHub CLI (gh auth login) or a GITHUB_TOKEN. Without either, forkguard still pushes the branch and prints a link so you can open the pull request yourself.
  • origin on github.com; clean tracked tree; on a branch.
  • gh auth, GITHUB_TOKEN or GH_TOKEN. Falls back to printing the compare URL.

#Description

Here is everything it does, in order:

  1. Creates a new branch called forkguard/remove-malware (or -2, -3 if that name is taken).
  2. Runs the same cleaning as `forkguard fix`.
  3. Takes committed .env files out of git while keeping them on your disk.
  4. Commits everything as “Remove injected malware”.
  5. Pushes the branch to GitHub.
  6. Opens the pull request with a description of what was removed and what to do next.
  7. Switches you back to the branch you were on.

The pull request tells reviewers what the malware does and what to do after merging: rotate tokens and keys from another device, block force pushes on the default branch, and run an antivirus scan.

#--upstream

Use this when you forked a repo and the original repo has the malware. The pull request goes to the original owner instead of your fork.

forkguard builds the fix on top of the original repo’s default branch, not your fork. This matters: if your fork is the infected one, a normal pull request would carry the malicious commit along with the fix. Building from the original keeps the pull request to exactly one commit, the fix. If the repo is not a fork, you get an error telling you to run forkguard pr without --upstream.

Creates forkguard/remove-malware[-N] from HEAD, or from the upstream default branch with --upstream. Runs scan and fix with untrackSecrets. Stages only changed paths, commits “Remove injected malware”, pushes to origin, opens a PR via gh or the API, then switches back. If no commit results, the branch is deleted and the tree is reset.

#Output

Output
forkguard  cleaning you/old-project on a new branch forkguard/remove-malware

  done  init                deleted
  done  postcss.config.mjs  restored your original from git history

  Pushing forkguard/remove-malware to you/old-project

  Pull request opened: https://github.com/you/old-project/pull/12

If it could not open the pull request itself, it still pushes and prints a link:

Output
  Branch pushed. Open the pull request here:
  https://github.com/you/old-project/compare/main...you:forkguard/remove-malware?expand=1
Output
Pull request opened: <url>
Branch pushed. Open the pull request here: <compare url>

#Notes

  • Nothing to clean: prints “has nothing to clean.” and leaves no branch behind.
  • Only never-committed files: when the only problem was a dropped file that was never committed (for example an untracked config.bat), it is deleted from your folder and forkguard says there is nothing to put in a pull request.
  • Your work is safe: the fix is built on a fresh branch. If anything fails before the commit, forkguard resets that branch, switches you back and deletes it.
  • Secrets: committed .env files are removed from git (git rm --cached) but kept on your disk, and .gitignore is updated so they stay out.

#Errors you may see

MessageWhat to do
This folder is not a git repoUse `forkguard fix` instead.
The origin remote is not on GitHubforkguard pr only works with repos on GitHub. Use forkguard fix.
You have uncommitted changesRun git stash, try again, then git stash pop.
You are not on a branchSwitch to the branch you want to clean first.
… is not a fork, so there is no upstreamRun forkguard pr without --upstream.
Nothing could be fixed automaticallyThe findings need a person. Run forkguard to read them.
  • Branch deleted and tree reset if no commit is made.
  • Detached HEAD, dirty tracked tree and non-GitHub origins are rejected.

#Exit status

CodeMeaning
0Clean, or only MED findings.
1Something HIGH was found.
2forkguard itself could not run, for example a failed push.

The same codes work in scripts and CI. See Exit codes.

0   clean, or MED findings only
1   a HIGH finding
2   error (for example a failed push)

#Examples

Fix your own repo:

gh auth login
git stash          # only if you have unsaved work
forkguard pr
git stash pop

Send the fix to the repo you forked from:

forkguard pr --upstream
You want to…Run
Clean your own repo on GitHubforkguard pr
Send the fix to the repo you forked fromforkguard pr --upstream
forkguard pr
forkguard pr --upstream

#See also

Where to next

Edit this page on GitHub View as Markdown

Type to search. Use the arrow keys and Enter.