John D
John D

Reputation: 23

git push origin [local-branch] tries to push into remote main branch instead of creating a new one

I have forked a foreign repository whose "main" branch is called develop (instead of master) and made several commits on this develop branch.
Now I want to create a new branch of the initial foreign repository's develop branch (and not the develop branch of the one I forked and worked on) so as to work without my previous changes from scratch, like so:

So I created a local branch called fix-3894 but whenever I use the "git push origin my-new-branch" command, I get this output:

! [rejected]        fix-3894 -> develop (non-fast-forward)

Basically, instead of transferring this local new branch on the remote repository, it tries to push it into the develop branch which is ahead of it and naturally faces a rejection. What I ultimately want is having both branches on the remote repository of mine, develop AND fix-3894.

Is my understanding of how branches work incorrect? I've been doing a lot of searching but haven't found anything to match my case.

Upvotes: 2

Views: 164

Answers (1)

VonC
VonC

Reputation: 1323233

You can do a git branch -avv to see if my-new-branch has origin/develop as an upstream branch. That would be strange, and maybe related to origin refspec.

If you want to force the upstream branch, do a:

git push -u origin my-new-branch:my-new-branch

Upvotes: 3

Related Questions