git push origin 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
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:
git fetch upstream(to get the latest copy of the foreign repo)
git checkout -b "my-new-branch" upstream/develop(create a new branch from
git push origin my-new-branch(push the branch to my remote repo on github)
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.
One Solution collect form web for “git push origin tries to push into remote main branch instead of creating a new one”
You can do a
git branch -avv to see if
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