3

I have finished the 2nd programming assignment in R (Coursera Course).
After that I did relate my local repo to the global repo on my GitHub account then I made a commit and push -u origin master.

But I got the following error:

 ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/RofaidaG/ProgrammingAssignment2' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first 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. 

Then I made a branch and checkout to the master then pull the repo in my get account but I received the below message:

 ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

How can I proceed?

2
  • Are you able to pull the master branch? Commented Mar 28, 2017 at 1:35
  • Are you sure you did a git pull after checking out to master again? Cause the answer seems the same as the failed git push above. Commented Mar 28, 2017 at 1:38

2 Answers 2

1

This will happen if you add a Licence or README file before you push your code into the repository.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That makes so much sense :) This should be mentioned in every single tutorial not to do when you want to start locally and then push to github. That's what caused so many issues for me every time i tried working with a new repository.
0

If your commits are on a dedicated branch, try instead:

git fetch git checkout mybranch (you might be already on that branch) git rebase origin/master git push -u origin mybranch 

But if your commits are on a local master branch, and if you are supposed to push on master, then:

git checkout master git fetch # replay your local commits on top of origin/master git pull --rebase # check everything is still working git push 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.