Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

(I'm hoping for an answer that isn't bitbucket specific, but will work for "moving" a git repository in any case.)

like image 467
kojiro Avatar asked Feb 28 '13 15:02

kojiro


People also ask

Does git work over SSH?

Git can use four distinct protocols to transfer data: Local, HTTP, Secure Shell (SSH) and Git.

How do I import existing git repository?

Select Repos, Files. From the repo drop-down, select Import repository. If the source repo is publicly available, just enter the clone URL of the source repository and a name for your new Git repository.


2 Answers

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://[email protected]/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.

like image 176
Marcus Avatar answered Sep 20 '22 20:09

Marcus


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://[email protected]/someuser/somerepo.git
git push -u origin --all   # to push changes for the first time
like image 40
tyteen4a03 Avatar answered Sep 20 '22 20:09

tyteen4a03