Migrating a GitHub repository to a new account can be done through several approaches depending on whether you want to retain the commit history, transfer ownership, or create a fresh repository. Here’s a detailed guide:
Option 1: Transfer Ownership
This is the best option if you want to retain the repository’s history and issues and fully migrate it to a new GitHub account or organization.
-
Prerequisites:
- You must have admin permissions for the repository.
- The new account must accept the transfer.
-
Steps:
- Go to the repository in the source account.
- Navigate to Settings > General.
- Scroll down to the Danger Zone section and click Transfer.
- Enter the repository name and the new owner’s GitHub username or organization.
- Confirm the transfer.
Once transferred, the repository is fully owned by the new account.
Option 2: Clone and Push to a New Repository
If you want to copy a repository without transferring ownership:
- Clone the Repository:
git clone https://github.com/old-account/repo-name.git
cd repo-name
-
Change the Remote URL:
- Create a new repository in the new account.
- Update the remote URL to point to the new repository:
git remote set-url origin https://github.com/new-account/repo-name.git
Push to the New Repository:
git push origin main
Replace
main
with the default branch of your repository.
- Update Submodules (if any): If your repository has submodules, update their URLs as well.
Option 3: Mirror the Repository
If you want to create an exact copy:
- Mirror Clone the Repository:
git clone --mirror https://github.com/old-account/repo-name.git
-
Push to the New Repository:
- Create a new repository in the new account.
- Push the mirrored repository:
cd repo-name.git git push --mirror https://github.com/new-account/repo-name.git
This ensures all branches, tags, and history are copied.
Notes:
-
Issues and Pull Requests:
- GitHub does not migrate issues, pull requests, or wikis automatically. Use third-party tools like
gh-issues-migrate
or export data manually.
- GitHub does not migrate issues, pull requests, or wikis automatically. Use third-party tools like
-
Repository Visibility:
- Ensure the new repository’s visibility (public/private) matches your preferences.
-
Webhook and Settings:
- Reconfigure any webhooks or integrations for the new repository.
This approach ensures your repository, history, and setup are correctly migrated to your new account!
Top comments (0)