DEV Community

Ajit Kumar
Ajit Kumar

Posted on

Transfer, Copy, or Mirror: Playing with Ownership of Github Repo: ChatGPT notes

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.

  1. Prerequisites:

    • You must have admin permissions for the repository.
    • The new account must accept the transfer.
  2. 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:

  1. Clone the Repository:
   git clone https://github.com/old-account/repo-name.git
   cd repo-name
Enter fullscreen mode Exit fullscreen mode
  1. 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
    
  2. Push to the New Repository:

   git push origin main
Enter fullscreen mode Exit fullscreen mode

Replace main with the default branch of your repository.

  1. 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:

  1. Mirror Clone the Repository:
   git clone --mirror https://github.com/old-account/repo-name.git
Enter fullscreen mode Exit fullscreen mode
  1. 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.
  • 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!

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is 100% worth it for your career.

Okay let's go

Community matters

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay