forkguard pr
Clean the repo on a new branch and open a pull request, so GitHub gets fixed too.
#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 --upstreamforkguard pr [folder] [--upstream]#Requirements
- The folder is a git repo whose
originis 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 aGITHUB_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:
- Creates a new branch called
forkguard/remove-malware(or-2,-3if that name is taken). - Runs the same cleaning as `forkguard fix`.
- Takes committed
.envfiles out of git while keeping them on your disk. - Commits everything as “Remove injected malware”.
- Pushes the branch to GitHub.
- Opens the pull request with a description of what was removed and what to do next.
- 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
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/12If it could not open the pull request itself, it still pushes and prints a link:
Branch pushed. Open the pull request here:
https://github.com/you/old-project/compare/main...you:forkguard/remove-malware?expand=1Pull 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
.envfiles are removed from git (git rm --cached) but kept on your disk, and.gitignoreis updated so they stay out.
#Errors you may see
| Message | What to do |
|---|---|
| This folder is not a git repo | Use `forkguard fix` instead. |
| The origin remote is not on GitHub | forkguard pr only works with repos on GitHub. Use forkguard fix. |
| You have uncommitted changes | Run git stash, try again, then git stash pop. |
| You are not on a branch | Switch to the branch you want to clean first. |
| … is not a fork, so there is no upstream | Run forkguard pr without --upstream. |
| Nothing could be fixed automatically | The 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
| Code | Meaning |
|---|---|
0 | Clean, or only MED findings. |
1 | Something HIGH was found. |
2 | forkguard 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 popSend the fix to the repo you forked from:
forkguard pr --upstream| You want to… | Run |
|---|---|
| Clean your own repo on GitHub | forkguard pr |
| Send the fix to the repo you forked from | forkguard pr --upstream |
forkguard pr
forkguard pr --upstream#See also
- `forkguard fix`
- Cleaning an infected project
- GitHub Action: open the fix automatically