A CLI tool that migrates GitHub pull requests from forks to branches in the main repository, preserving commit history and authorship.
git-mfpr (Git Migrate Fork PR) helps maintainers bring pull requests from forked repositories into their main repository as regular branches. This is useful when you want to:
- Continue work on a PR after the original author has abandoned it
- Run CI/CD pipelines that don't work well with forks
- Collaborate more easily on a contribution
- Maintain a cleaner repository structure
While you could manually run gh pr checkout and git push, git-mfpr provides significant value through:
- Validates PR is from a fork (prevents mistakes on same-repo PRs)
- Checks if branch already exists (no accidental overwrites)
- Verifies PR is still open (no dead PR migrations)
- Simple branch naming (consistent, predictable names)
- One command instead of 3-4 manual steps
- Batch processing (multiple PRs at once)
- Dry-run mode (preview actions before executing)
- Consistent commit messages and PR descriptions
- Standardized process across your entire team
- Reduced onboarding time (new contributors learn one command)
- Prevents human error (forgot to push, wrong branch name, etc.)
- Documentation (the process is codified in the tool)
- GitHub Action integration for automated workflows
- Scheduled cleanup of abandoned PRs
- Non-interactive operation (works in automated environments)
- CI/CD pipeline integration (migrate PRs as part of your workflow)
# Instead of manually checking each PR status and running commands
git-mfpr 123 124 125 # Batch migrate multiple abandoned PRs# New team member doesn't need to learn the manual process
git-mfpr 123 --dry-run # Shows them exactly what will happen# GitHub Action to automatically migrate PRs that pass CI but are abandoned
- uses: yourusername/git-mfpr@v1
with:
pr-ref: ${{ needs.ci.outputs.pr-number }}Perfect for:
- Managing multiple repos with frequent fork PRs
- Team environments where consistency matters
- Automation needs (CI/CD, scheduled cleanup)
- High-volume PR management
- Reducing cognitive load and preventing mistakes
May not be worth it for:
- Occasional use (once a month)
- Single-person projects
- Simple workflows with just a few commands
Bottom line: It's a quality-of-life tool that shines in team environments and automation scenarios, not just time-saving for individual use.
- 🔄 Preserves complete commit history and authorship
- 🚀 Simple one-command migration
- 🎯 Simple, consistent branch naming with PR number
- 🔍 Dry-run mode to preview actions
- 📦 Batch migration support for multiple PRs
- 🛡️ Safety checks to prevent accidental overwrites
- Git
- GitHub CLI (
gh) - must be installed and authenticated
go install github.com/cabljac/git-mfpr/cmd/git-mfpr@latestDownload the latest release for your platform from the releases page.
# Migrate PR #123 from the current repository
git-mfpr 123
# Migrate multiple PRs
git-mfpr 124 125
# Migrate from a specific repository
git-mfpr owner/repo#123
# Migrate using full GitHub URL
git-mfpr https://github.com/owner/repo/pull/123--dry-run # Preview what would happen without making changes
--no-push # Create local branch but don't push to origin
--no-create # Don't offer to create a new PR
--branch-name string # Use custom branch name (single PR only)You can use git-mfpr directly in your terminal, or as a custom git command:
# Migrate PR #123 from the current repo (dry run)
git-mfpr 123 --dry-run
# Migrate a PR from a specific repo
git-mfpr owner/repo#456
# Use as a custom git command (if installed as git-mfpr)
git mfpr 789
# With custom branch name
git-mfpr 123 --branch-name=my-feature-branchAdd this step to your workflow (e.g., .github/workflows/migrate.yml):
name: Migrate Fork PRs
on:
workflow_dispatch:
inputs:
pr-ref:
description: 'PR reference (number, URL, or owner/repo#number)'
required: true
jobs:
migrate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Migrate PR from fork to branch
uses: yourusername/git-mfpr@v1
with:
pr-ref: ${{ github.event.inputs.pr-ref }}
dry-run: 'true' # optional
no-push: 'false' # optional
no-create: 'false' # optional
branch-name: '' # optionalReplace yourusername with your actual GitHub username.
| Name | Description | Required | Default |
|---|---|---|---|
| pr-ref | PR reference (number, URL, or owner/repo#number) | Yes | |
| dry-run | Show what would happen without executing | No | false |
| no-push | Do not push branch | No | false |
| no-create | Do not create PR | No | false |
| branch-name | Custom branch name | No |
git-mfpr 123 --dry-runOutput:
🔄 Migrating PR #123...
📋 Title: Fix memory leak in worker pool
👤 Author: johndoe
🌿 Branch: migrated-123
$ git checkout main (dry-run)
$ git pull origin main (dry-run)
$ gh pr checkout 123 -b migrated-123 (dry-run)
$ git push -u origin migrated-123 (dry-run)
✅ Migration complete!
git-mfpr 123 --branch-name feature/awesome-featuregit-mfpr 123 --no-push- Fetches PR Information: Uses
ghCLI to get PR details - Validates: Ensures PR is from a fork and is still open
- Creates Branch: Generates a branch name like
migrated-123 - Checks Out Code: Uses
gh pr checkoutto fetch the PR commits - Pushes to Origin: Pushes the new branch to your repository
- Suggests Next Steps: Provides the command to create a new PR
By default, branches are named using the pattern:
migrated-{number}
For example:
migrated-123migrated-456
This simple naming convention ensures consistent and predictable branch names.
# Clone the repository
git clone https://github.com/cabljac/git-mfpr.git
cd git-mfpr
# Build
make build
# Run tests
make test
# Install locally
make installgit-mfpr/
├── cmd/git-mfpr/ # CLI entry point
├── internal/
│ ├── git/ # Git operations
│ ├── github/ # GitHub API interactions
│ ├── migrate/ # Core migration logic
│ └── ui/ # Terminal UI
├── Makefile
└── README.md
The tool provides clear error messages for common issues:
- Not in a git repository: Run the command from within a git repository
- gh CLI not installed: Install from https://cli.github.com/
- PR not found: Check the PR number and repository
- Branch already exists: Use
--branch-nameto specify a different name - PR not from fork: Only PRs from forks need migration
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details
Built with:
- Cobra for CLI framework
- GitHub CLI for GitHub API access