Two-step git import over ssh

Bitbucket has an importer tool for importing repositories from remote locations, but it only supports the git:// protocol. Our existing repositories are on a company controlled machine behind a firewall that I can’t change, and git:// is not available. I need to move the repositories from our company machine to bitbucket, keeping all history and details from the original repository intact.

Is there some way I can accomplish this by cloning the original repository via ssh to a local machine, and then pushing that repository to a newly-bare-initted repository on bitbucket? Will I lose any history or data that way?

  • Git Workflow with Bitbucket
  • bitbucket access not working
  • Error deploying to Azure through git (bitbucket hosted git repo)
  • How to structure Git repo for multi-tier architecture
  • Bitbucket git push as user
  • GIT pulling or cloning repository only gets Master branch
  • (I’m hoping for an answer that isn’t bitbucket specific, but will work for “moving” a git repository in any case.)

  • Git best practice one or multiple branches
  • Git: How to recover a file after a pull / failed auto merge?
  • GIT: Have current commit hash and latest tag in file on commit
  • Create new repo by 'git remote add origin' and 'push'
  • git is very very slow when tracking large binary files
  • How would I mount docker container filesystem?
  • 3 Solutions collect form web for “Two-step git import over ssh”

    You’ll want to be sure you have the entire history. You can do this by performing a full local bare clone first.

    git clone --mirror git://LOCAL_URL/somerepo.git
    

    Then add the remote and push as Timothy pointed out. Though, you probably want to use something other than origin for the remote alias.

    git remote add bitbucket ssh://git@bitbucket.org/someuser/somerepo.git
    git push -u bitbucket --all
    

    This could be used for any Git hosting service. Simply replace the remote URL with anything you’d like.

    From what I know cloning the entire repo and pushing it works. Bitbucket even has the command for you:

    cd /path/to/my/repo
    git remote add origin ssh://git@bitbucket.org/someuser/somerepo.git
    git push -u origin --all   # to push changes for the first time
    

    What makes you think that we only support the git:// protocol? We support the smart http protocol and so for instance you can just import https://github.com/jquery/jquery

    So if your repo is accessible from the Internet and does HTTP(S) then you should have no problem using the importer (which does a proper clone and do preserves history).

    Git Baby is a git and github fan, let's start git clone.