How to Push One Repo to Two GitHub Accounts

& DevOps Practitioner

& DevOps Practitioner
Sometimes you need one local repository to publish to two remote destinations. This can be useful during migrations, mirroring, backup, or when two systems depend on different remotes.
Common legitimate use cases include:
- Migration period: push to old and new remotes while teams transition.
- Mirror/backup remote: keep a secondary host up to date for resilience.
- Automation split: one remote used by internal CI/CD, another used by external tooling.
- Upstream/downstream workflow: maintain compatibility with two repository locations.
Steps:
- Configure SSH host aliases for account-specific keys
- Keep one fetch remote and configure two push URLs
- Verify that one push targets both repositories
- Use normal daily workflow
- Know how to rollback to single-remote push
Step 1: Configure SSH host aliases for account-specific keys
In ~/.ssh/config, define host aliases so each remote uses the correct key:
Host github-primary
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_primary
IdentitiesOnly yes
Host github-secondary
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_secondary
IdentitiesOnly yes
This allows Git to choose the right SSH identity per remote destination.
Step 2: Keep one fetch remote and configure two push URLs
Use origin as your main remote, keep fetch pointed at your primary repo, and add both push targets:
# Ensure primary push URL
git remote set-url --push origin git@github-primary:your-org/your-repo.git
# Add secondary push URL
git remote set-url --add --push origin git@github-secondary:your-backup-org/your-repo.git
With this setup:
- fetches still come from
origin - pushes go to both configured repositories
Step 3: Verify that one push targets both repositories
Check remote config:
git remote -v
Expected output pattern:
origin git@github-primary:your-org/your-repo.git (fetch)
origin git@github-primary:your-org/your-repo.git (push)
origin git@github-secondary:your-backup-org/your-repo.git (push)
Test safely without writing:
git push --dry-run origin main
You should see both push targets in the command output.
Step 4: Use normal daily workflow
No special workflow is needed after setup.
git push origin main
That single command pushes the same commits to both remotes.
Step 5: Rollback to single-repo push (if needed)
If you decide to stop dual-pushing, reset to one push URL:
git remote set-url --push origin git@github-primary:your-org/your-repo.git
git remote -v
Notes
- This mirrors commit pushes only; it does not sync pull requests, issues, labels, or settings.
- If one remote rejects push (permissions/auth), Git will report it and you can retry after fixing access.
