Migrating a Git repo with full history

Moving a Git repository to another (or from one hosting platform like Bitbucket to another like GitHub) while preserving the full history, including all commits and branches, is relatively straightforward.

Here's how you can do it:

  1. Clone the existing repository:
    • Open your terminal or command prompt.
    • Navigate to the directory where you want to clone the repository.
    • Run the following command to clone the repository from Bitbucket:
      git clone --mirror

      Replace username with your Bitbucket username and repository with the name of your repository.

  2. Create a new repository on GitHub:
    • Log in to your GitHub account.
    • Click on the "+" icon in the top-right corner and select "New repository".
    • Give your repository a name and set the visibility (public or private).
    • Click on "Create repository".
  3. Push the cloned repository to GitHub:
    • In your terminal or command prompt, navigate to the cloned repository's directory.
    • Run the following command to push the repository to GitHub:
      git push --mirror

      Replace username with your GitHub username and repository with the name of your new GitHub repository.

  4. Update the remote URL (optional):
    • If you want to continue working with the repository, you can update the remote URL to point to the new GitHub repository. Run the following command:
      git remote set-url origin

Next Step: Rename master branch to main and make it the default

Leave a Reply

Your email address will not be published. Required fields are marked *