0

I'm new to Git.

I created a brand new branch on a newly cloned repo. I want to push my work to the develop branch. I have only done 1 commit.

I did my work and did the following:

git add .
git commit -m "message"
git checkout develop
git pull origin develop
git checkout my-branch
git merge develop
git push origin develop

But I get the classic error:

 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to '[email protected]:project/project.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So I made sure my branch and develop were up to date - no worries, they are. So I tried again and got the same message.

I then made sure I don't have any other branches.

I'm not sure what else I can do. Would anyone know?

1
  • @matt but there's no where to pull mybranch from. It hasn't been pushed before
    – MeltingDog
    Commented Apr 23, 2020 at 5:47

1 Answer 1

1

Your current branch is my-branch, not develop. You cannot push from it to develop.

git checkout develop
git merge my-branch
git push
12
  • Thanks, so how do I make a pull request for my branch?
    – MeltingDog
    Commented Apr 23, 2020 at 5:52
  • You said "I want to push my work to the develop branch." Now you say you want to create a pull request. These goals contradict to each other.
    – mentallurg
    Commented Apr 23, 2020 at 5:56
  • When you pushed to developed, you cannot create PR, because there is nothing to merge any more.
    – mentallurg
    Commented Apr 23, 2020 at 5:58
  • 1
    See your last command: you are in the my-branch, but you are trying to push to develop. This is not right. You should push to the origin my-branch, i.e. to the remote counterpart of your local my-branch.
    – mentallurg
    Commented Apr 23, 2020 at 6:10
  • 1
    If you have no service such remote branch, git will show you command how you can create it.
    – mentallurg
    Commented Apr 23, 2020 at 6:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.