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 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:

  • 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 upstream/develop)
  • 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:

  • branch with no common ancesters
  • Use Git branches for book chapters
  • GitHub compare view for current versions of branches
  • Git: Best way to add only some parts of a file from another branch?
  • Stop new branch from getting old commit history in Git
  • Is Feature Branching still (or ever) considered a bad practice?
  • ! [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.

  • Git push to non-bare repository confusion
  • Windows 10 file permission error with Github
  • git svn dcommit without rebasing
  • Git: pull doesn't get up-to-date squashed commit
  • Git automatically declaring subprojects as submodules?
  • Why git decide that my file is binary
  • 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 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
    
    Git Baby is a git and github fan, let's start git clone.