Today I encountered a strange circumstance and felt the need to document it. Bitbucket has some decent documentation, but sometimes it doesn’t cover every scenario you might encounter as a developer. I have a client who, for reasons unimportant to this discussion, had to abruptly terminated her relationship with her previous developer. This left me with a git repository containing unstaged and uncommitted code. I wanted to the code and the git history into my new bitbucket repository. But I encountered problems. Bitbucket’s instructions for this procedure are here.

I tried the second scenario on that page. But I got errors when trying to run git push --all bitbucket

Eventually, I got it working by doing a little extra work. Assume the following:

[oldgit] = your old git repo you want to import
[tempgit] = a bare copy of your old git
[newgit] = your new git repo that you import into bitbucket

First, make sure you have added and committed everything
From [oldgit] dir:

git add .
git commit -m "Whatever you want to say"

From a directory where you want to clone your [tempgit] into a bare repository:

git clone --bare file:///path/to/[oldgit] [tempgit]

Now clone a local copy and do your import:

git clone file:///path/to/[tempgit] [newgit]
cd [newgit]
git remote add bitbucket [your git repo url at bitbucket]
git push --all bitbucket
git push --tags bitbucket

The bare repository didn’t seem to like not knowing where it’s original origin was. But once I cloned a local copy from it, everything worked fine. I haven’t tested, but I’m sure these instructions would work at another git host/server as well.