How to move git repository with all branches from bitbucket to github?

前端 未结 11 1763
孤城傲影
孤城傲影 2020-12-02 03:21

What is the best way to move a git repository with all branches and full history from bitbucket to github? Is there a script or a list of commands I have to use?

相关标签:
11条回答
  • 2020-12-02 03:47

    Here are the steps to move a private Git repository:

    Step 1: Create Github repository

    First, create a new private repository on Github.com. It’s important to keep the repository empty, e.g. don’t check option Initialize this repository with a README when creating the repository.

    Step 2: Move existing content

    Next, we need to fill the Github repository with the content from our Bitbucket repository:

    1. Check out the existing repository from Bitbucket:
        $ git clone https://USER@bitbucket.org/USER/PROJECT.git
    
    1. Add the new Github repository as upstream remote of the repository checked out from Bitbucket:
        $ cd PROJECT
        $ git remote add upstream https://github.com:USER/PROJECT.git
    
    1. Push all branches (below: just master) and tags to the Github repository:
        $ git push upstream master
        $ git push --tags upstream
    

    Step 3: Clean up old repository

    Finally, we need to ensure that developers don’t get confused by having two repositories for the same project. Here is how to delete the Bitbucket repository:

    1. Double-check that the Github repository has all content

    2. Go to the web interface of the old Bitbucket repository

    3. Select menu option Setting > Delete repository

    4. Add the URL of the new Github repository as redirect URL

    With that, the repository completely settled into its new home at Github. Let all the developers know!

    0 讨论(0)
  • 2020-12-02 03:48

    In case you couldn't find "Import code" button on github, you can:

    1. directly open Github Importer and enter the url. It will look like: Screenshot of github importer
    2. give it a name (or it will import the name automatically)
    3. select Public or Private repo
    4. Click Begin Import

    UPDATE: Recently, Github announced the ability to "Import repositories with large files"

    0 讨论(0)
  • 2020-12-02 03:50

    It's very simple.

    1. Create a new empty repository in GitHub (without readme or license, you can add them later) and the following screen will show.

    2. In the import code option, paste your Bitbucket repo's URL and voilà!!

    Click Import code

    0 讨论(0)
  • 2020-12-02 03:54

    Simplest way of doing it:

    git remote rename origin repo_bitbucket
    
    git remote add origin https://github.com/abc/repo.git
    
    git push origin master
    

    Once the push to GitHub is successful, delete the old remote by running:

    git remote rm repo_bitbucket
    
    0 讨论(0)
  • 2020-12-02 03:57

    I had the reverse use case of importing an existing repository from github to bitbucket.

    Bitbucket offers an Import tool as well. The only necessary step is to add URL to repository.

    It looks like:

    Screenshot of the bitbucket import tool

    0 讨论(0)
  • 2020-12-02 03:57

    In case you want to move your local git repository to another upstream you can also do this:

    to get the current remote url:

    git remote get-url origin

    will show something like: https://bitbucket.com/git/myrepo

    to set new remote repository:

    git remote set-url origin git@github.com:folder/myrepo.git

    now push contents of current (develop) branch:

    git push --set-upstream origin develop

    You now have a full copy of the branch in the new remote.

    optionally return to original git-remote for this local folder:

    git remote set-url origin https://bitbucket.com/git/myrepo

    Gives the benefit you can now get your new git-repository from github in another folder so that you have two local folders both pointing to the different remotes, the previous (bitbucket) and the new one both available.

    0 讨论(0)
提交回复
热议问题