-5

I tried saving my django project to github, but I am getting an error after running the git push command

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/kp1311/Careerboost'
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.
Daemon Painter
  • 3,208
  • 3
  • 29
  • 44

1 Answers1

1

This error message can be found many times in StackOverflow, but when googling it, the first two results are quite hard to grasp.

You are pushing to a branch (either master or something else) that you cloned locally some time ago. However, in the meanwhile, somebody else pushed new content to that remote branch.

In order to be able to push, you must do one of the following:

git push -f

This will override the remote content with your content. Everything that the other person modified is now replaced by your content (since the first diverging commit)

git pull + rebase

This is not a single command, but I'm in a bit of a rush so I'll just outline it here: first, stash away your edits and remove your commit (git reset --soft and git stash) then git pull then git stash pop and git commit.

Now you can git push and it will have your edits on top of the other people edits. You'll have to solve conflict manually.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44