markstewie
markstewie

Reputation: 9587

Pushing to remote branch

I have a git problem/question.

We are using bitbucket as our remote repo. Until now we've only had the master branch.

The other person I'm working on this with created a "develop" branch now the project is live for us to continue working on.

I've been working locally and have made changes and commited them.

I now want to push these to the remote "develop" branch.

I thought that

git push origin develop

would do it but i get

error: src refspec develop does not match any.

What does this mean?. I can see that the develop branch does indeed exist so what am I doing wrong?

Thanks so much for your help!

Upvotes: 3

Views: 1192

Answers (5)

Munir Husseini
Munir Husseini

Reputation: 489

Did you forget to commit your work? This happens when you clone an empty repo, add files but forget to commit them before pushing.

Upvotes: 1

powlo
powlo

Reputation: 2728

If you use

git push <repo> <src>

eg, git push origin develop

then git expects to find a local branch called 'develop' that it can take to push to a remote branch of the same name. Since there is no local branch of that name you get the error.

So, if you want to push to a new (or existing) remote branch that has a different name locally then you would do the following:

git push <repo> <src>:<dst>

eg,

git push origin master:develop

That should work. *checks*. It does.

Upvotes: 1

markstewie
markstewie

Reputation: 9587

Thanks for your answers, I've got things working again.

For anyone interested this is how I did it.

I did a

git pull origin master

and that updated my local repo and it was now aware there was a remote develop branch

I then did

git checkout develop

to switch to my local develop branch.. then

git merge master

to merge all the changes I had done in master into the develop branch Then doing

git push origin develop

worked fine.

Now all my changes are safe in the develop branch I can revert the master branch (where I was working) so it's the same as the remote master branch and everything is as it should be.

Not sure If that was the easiest way to go about it but I learned a lot about git.

Thanks again for your answers.

Upvotes: 3

Bill Door
Bill Door

Reputation: 18956

You have not yet pulled develop from the server. You have a remote develop branch, but you do not have a local develop tracking branch.

git checkout develop

This will create the local develop tracking branch.

If you already committed your changes, those changes are on the master branch that you were using before. Moving those changes to the develop branch is a bit more complicated.

Moving those changes can be explained once we've identified the problem that you are actually having.

Upvotes: 0

J-16 SDiZ
J-16 SDiZ

Reputation: 26920

develop exist in where? local? remote? or both? Try:

git push origin HEAD:develop

Upvotes: 1

Related Questions