convert-to-fork
v1.0.1
Published
Rename origin to upstream, fork the repo via the GitHub REST API (no gh CLI needed), and point origin at your fork.
Maintainers
Readme
convert-to-fork
Turn a clone into a fork setup, in one command — no gh CLI required.
origin (some-org/repo) ──┐
├──► upstream = some-org/repo
origin (you/repo, new fork) ◄┘ origin = you/repo (created via GitHub API)What it does
- Renames the current
originremote toupstream. - Calls the GitHub REST API to fork that repo under your account.
- Adds a new
originremote pointing at your fork. - Fetches
origin(retrying briefly while GitHub finishes provisioning the fork).
Install
npm install -g convert-to-forkOr run it without installing:
npx convert-to-forkUse
Inside any git repo whose origin points at a GitHub repo you don't own:
convert-to-forkThat's it — no arguments needed. It reads origin, authenticates, forks, and rewires the remotes.
Auth
You need a GitHub token with public_repo scope (or repo for private repos):
- Set
GITHUB_TOKEN(orGH_TOKEN) in your environment, or - Pass
--token <token>, or - Just run it — you'll be prompted for one (input is masked).
The first time you run it, you'll be prompted for a token once — it's then saved to ~/.convert-to-fork/config.json (mode 0600) so you're never asked again. Update it later with:
convert-to-fork --change-githubOptions
convert-to-fork [--ssh | --https] [--token <token>]
convert-to-fork --change-github
convert-to-fork -v
--ssh Force the new origin to use SSH ([email protected]:...)
--https Force the new origin to use HTTPS (https://github.com/...)
--token <token> GitHub token for this run only (not saved)
--change-github Update your saved GitHub token
-v, --version Show version and build credit
-h, --help Show helpBy default the new origin uses the same protocol (SSH or HTTPS) as the original origin had.
Token resolution order: --token flag → $GITHUB_TOKEN/$GH_TOKEN → saved token → interactive prompt (saved for next time).
Notes
- Fails fast and rolls back the
origin→upstreamrename if the fork can't be created (e.g. you already own the repo, or auth fails). - Refuses to run if an
upstreamremote already exists, so it never clobbers one you've already set up. - Works against GitHub Enterprise hosts too (uses
https://<host>/api/v3), based on the host in your existingoriginURL. - Requires Node.js 18+ (uses the built-in
fetch). Zero npm dependencies.
License
MIT
