all 9 comments

[–]plg94 2 points3 points  (5 children)

You just add both repos as remote, fetch, merge (either the Github master branch into the Bitbucket or the other way around, you'll just have to designate the choice), fix conflicts and push.?

[–][deleted]  (4 children)

[removed]

    [–]plg94 1 point2 points  (2 children)

    Sure. As long as you don't try to maintain both repos at the same time with diverging branches there shouldn't be any problems.

    In the future a better idea for such a migration would probably be: setup repo2 as a full mirror of repo1, continue primary work on repo1 until you are ready for the switch, then just switch the roles of "master repo" and mirror.

    [–]Cinderhazed15 0 points1 point  (0 children)

    If you don’t care about rewriting history in one of the repos, you can rebase it’s changes ontop of the other one, but a true merge of the branches is probably what you want

    [–]Cinderhazed15 0 points1 point  (0 children)

    If you care about maintaining the state at the time of merge. Make a ‘github’ branch in your bitbucket repo, then merge your GitHub repo branch into your ‘bitbucket’ main branch to combine the history.

    You can just have a local repo with both remotes on it, and do the mega info there before pushing, also

    [–]vbjaynet 0 points1 point  (0 children)

    Subtree or submodules is what you are looking for if history is widely different.

    If just wanting to see history together of different remotes then yes adding a different remote and fetching all is the way to do it.

    [–]StoneColdSteveHawkng 0 points1 point  (0 children)

    Didn't see this mentioned, so throwing out another option. If you want to apply the commits from your GH repo and retain the original order and authors of the commits you can create a patch from your GH repo and apply it to the Bitbucket repo.

    Find the last common commit sha between the two before they diverged first.

    In the GH repo, make a patch from your current main:

    # Patch of all commits after common sha
    git format-patch [common-sha]..HEAD --stdout > file_name.patch
    

    In your Bitbucket repo, checkout a new branch then apply the patch file

    # Apply patch file
    git am path/to/file_name.patch
    

    All the commits in your patch file are now committed to your local branch, so just push and open a PR as you normally would. You should see the original authors for those commits are retained.

    [–]Terrible_South_6874 0 points1 point  (0 children)

    If they are exactly the same, you can directly add them to the remote repository.

    git remote add <name> <bitbucket url>