Why did my branch not import?

Hello,

I just transferred a project from a Bonobo repository to BitBucket. (see topid: https://answers.atlassian.com/questions/41476794). The transfer seemed to work fine except it seems to have only transferred the main branch.

In SourceTree, which is still pointing to the Bonobo server, you can see the two branches in the following screen shot:

branches in SourceTree.png

I have the blue branch and the purple branch. I also drew an arrow to a commit on the blue branch in order to highlight an example of a commit that doesn't seem to have transferred over.

In my Bitbucket account, if I look at my commits, I don't see this particular commit (new build: 15.1.237):

commits on bitbucket.png

If I click on the Branches tab, I see this:

branches on bitbucket.png

So it doesn't seem like the blue branch got transferred over.

That actually might be OK because I'd much prefer to transfer it over into a completely separate repository, not a branch. Is that possible?

2 answers

Hi Gibran - so in the local repo where you did the migration run a 'git branch -a' How many branches do you have?  If the number is low, simply check them out and then push them to the 'target' remote you established. If you have a lot, (say over a dozen) there is a refspec that you can use that will push them all at once, except I have to look that up... smile

 

-Rich

Thanks Rich,

Before I do that, however, do you know if I can push the branch to a separate repository? That's really what we should have done at first as these two branches represent completely different versions of the same application (i.e. not different lines of development but different end products).

Sure - you just need to create another remote to an empty repo and push only the branch(es) you want.  If you look up in the git manual, you can change the branch name along the way so for example push the xyzProduct branch to master in that repo

 

-Rich

Hi Rich,

Following the procedure you provide at my other post: https://answers.atlassian.com/questions/41476794 ... I skipped step 1 (git clone --mirror src-repo-spec) because the repository has already been clone to .../repos/Profiler.git (*hopefully* with the branch).

Step 2 (git remote add target target-spec) gave me a bit of trouble. It said: "fatal: remote target already exists."

Ok, so if it already exists, I'll move onto step 3 (git push --all target). <-- This is where pushing the branch comes in (if I understand correctly).

I found this site which explains how to push a branch: http://stackoverflow.com/questions/5423517/how-do-i-push-a-local-git-branch-to-master-branch-in-the-remote ... in particular, the line that says: 

git push <remote> <local branch name>:<remote branch to push into>
So I typed: git push target Profiler_Legacy:master (Profiler_Legacy is what the branch is called in SourceTree). It gave me the error:

src refspec Profiler_Legacy does not match any.

failed to push some refs to 'https://gibran_shah@bitbucket.org/acmriskalive/risk-alive-prodiler-2.git'

...which alarms me because I thought I changed the target to https://gibran_shah@bitbucket.org/acmriskalive/profiler-legacy.git

But anyway, I also tried: git push https://gibran_shah@bitbucket.org/acmriskalive/profiler-legacy.git Profiler_Legacy:master ... but it gave me the same error.

I understand you said the way to push branches is in the git manual but I didn't find any examples that show how to do it in my specific case.

Thanks for your help.

 

Hi Gibran:

  1. You're right you only need to clone the repo once.
  2. The git remote add command adds a new remote.  The one we used first was named target, so you need to supply a new name, one for each of the repositories you want to work with remotely.
  3. Since you already pushed to the target earlier, you really don't want to change it's master branch, again you need to have different remotes to work with different remote repos.
  4. Depending on the state of the local repo, you may need to use a refspec like origin/Profiler_Legacy

 

git push newTarget origin/Profiler_legacy:master

 

Have a look a the command reference about remotes and pushing: https://www.git-scm.com/docs

Thanks for clarifying, Rich.

I tried "git push target2 origin/Profiler_Legacy:master" and variants thereof but I keep getting the same error:

src refspec origin/Profiler_Legacy does not match any.

failed to push some refs to https://gibran_shah@bitbucket.org/acmriskalive/profiler-legacy.git

Is it possible that the branch didn't get cloned? Is there a way to see what branches have been cloned locally?

0 votes

Hi @Gibran Shah,

As of Bitbucket Server 4.9 you can also import repositories using the web interface with our new Repository Importer

Hi John,

Thanks for the response.

I'm not sure if I'm connected to the Bitbucket Server 4.9 when I log into my Atlassian account. Supposing that I am, though, I don't exactly get an "Import Repository" option in the left-hand panel. I can, however, view my repositories and click on the one I want. That takes me to the repository setup page where I can click on "I have an existing project" and then "try our importer".

However, when I get to the importer page, I get this error when I type in the source URL:

unsupported protocol.png

Notice that it's telling me that I have entered an invalid protocol (http://) even though one of the suggestions it gives me is exactly the same protocol.

Also, supposing I get this right, how do I specify a particular branch?

Thanks very much for your help.

Hi Gibran,

I see now, you're using Bitbucket Cloud, which has a slightly different feature set than Bitbucket Server, which is why the importer is slightly different.

I just tried to import a repository myself which worked ok, but if I place a space before the URL, that's when I get the same error as you are getting. I've raised an issue at https://bitbucket.org/site/master/issues/13326/leading-and-trailing-spaces-should-be to track this.

For the moment, removing any leading or trailing whitespace from your git URL should allow you to import.

Edit: With regards to how to select a branch, there is no need as the importer will import all branches from the source repository.

Thanks!

Thanks for the reply John,


The warning about the invalid protocol stills shows up for me even without any whitespace surrounding the URL. (Not sure if this is preventing me from importing as I haven't tried yet).


I would actually like to select a specific branch from the source since I want to turn that branch into the main branch (with no other branches) in the target repository. Is that possible?


Thanks

If all you're after is the single branch to be the new default branch of the new repository, the importer is probably not for you and it would in fact be relatively easy to do this with a few git commands. When you create a new repository on bitbucket.org on its overview page there will be some instructions you can follow to push up code from an existing project.

Ok, the instruction I see are:

$ cd /path/to/my/repogit

$ remote add origin https://gibran_shah@bitbucket.org/acmriskalive/profiler-legacy.git

 $ git push -u origin --all # pushes up the repo and its refs for the first time

 $ git push origin --tags # pushes up any tags

Adding the origin seems to work fine (I get no errors), but then when I try to push my branch like this:

$ git push -u origin Profiler_Legacy:master

it tells me:

error: src refspec Profiler_Legacy does not match any.

error: failed to push some refs to 'https://gibran_shah@bitbucket.org/acmriskalive/profiler-legacy.git

"Profiler_Legacy" is what I called the branch in SourceTree. Is there any way to check what branches exist in the origin?

Hi Gibran,

If you did a git push -u origin --all then all branches should now be on the remote. You can then go in to the repository settings and change the main branch of the repository to be Profiler_Legacy.

I have a feeling the branch isn't in the source repository. In sourceTree, the Profiler_Legacy branch is the blue line and the master is the purple:

 SourceTree branches.png

When I have the master branch selected and I go to Repository > Repository Settings, the path says:

http://gshah@acm3/Bonobo.Git.Server/Profiler.git

When I have the Profiler_Legacy branch selected and I go to Repository > Repository Settings, the path says:

C:\Users\gshah\Source\Repos\Profiler

I interpret this to mean that the branch isn't uploaded to the Bonobo server. This is probably why I'm having trouble finding it.

The branch isn't that long (only a few nodes) so I think I might upload the original source code to the Bitbucket server and make incremental changes until I've mimic the entire Profiler_Legacy branch.

I see that the top commit has the label "origin/Profiler_Legacy" that means that the branch is present on the remote git server. However, it might be that origin is still pointing to your Bonobo server. To check this, in SourceTree, go to Repository > Repository Settings > Remotes tab, and check that "origin" is pointing to your Bitbucket repository. If it isn't, you should be able to edit the origin remote and then hit Push on the toolbar in the main SourceTree window to push up all the branches that you would like to push up to Bitbucket.

The origin under the Remotes tab says "C:\Users\gshah\Source\Repos\Profiler". So it's not point to Bitbucket.

If I hit "Edit Config File..." I see that I can set the remote "origin" url.

If l go my Profiler Legacy repository in Bitbucket and click on "I have an existing project", it gives me these git commands:

$ cd /path/to/my/repo

 $ git remote add origin https://gibran_shah@bitbucket.org/acmriskalive/profiler-legacy.git

 $ git push -u origin --all # pushes up the repo and its refs for the first time

 $ git push origin --tags # pushes up any tags

I'm assuming that it's the second line (with the origin url) that I can put into the config file. If I do that, and then hit push in SourceTree, this will push the Profiler_Legacy branch to my Bitbucket Profiler Legacy repository. Is this what you're saying?

Yes smile 

If you set the origin to that URL, you should then be able to push up your branch. 

If SourceTree shows you the origin can also edit a it easily in SourceTree, no need to go in to the git config if you're already in SourceTree. 

Simply go to the remotes configuration and click on the remote you want to edit, and then click the "Edit" button

 

And then edit the configuration for that remote:

You should now be able to push up your branch to Bitbucket.

Thanks John,

That worked. The Profiler Legacy branch is pushed to my bit bucket account.

However, it also seemed to push the main branch and they look like they're merged together. But that's OK. The Legacy branch is in there and it's in a separate repository from the main branch (even though a copy of the main branch is merged into the Legacy repository). I can just ignore the main branch stuff that got merged and focus only on the Legacy branch stuff for the Legacy repository, so it works in the end.

Thanks.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

434 views 6 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you