0

I can't update the source code in the repository on github.com using the following command.

$ git push -u origin master

The following error is displayed:

! \[rejected\]        master -\> master (fetch first)
error: failed to push some refs to 'https://github.com/\<username\>/my-history.git'
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.

Is there any way to do this?

I want to push the source code in the my repository.

Christian
  • 4,902
  • 4
  • 24
  • 42
  • 1
    The error message is rather clear: `You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.` Did you try this first? – Olivier Grégoire Mar 29 '22 at 09:38
  • Yes, I tried. But the following message is displayed. From https://github.com/Dream0804/my-history * branch master -> FETCH_HEAD Already up to date. –  Mar 29 '22 at 09:43

1 Answers1

-2

I experienced something similar to this a few days ago.

You can do something like this:

$ git remote add origin https://github.com/username/my-repo.git
$ git push -f origin master
Dream180
  • 180
  • 1
  • 13
  • `push -f` should not the only solution here. It overwrites the remote history. I would go for `git pull` first when I see the `failed to push some refs` error. Maybe someone else changed thing and the HEAD is not up-to-date anymore, see https://stackoverflow.com/questions/16493055/git-doesnt-seem-to-pull-all-updates-head-and-origin-head-in-different-positio – Christian Mar 29 '22 at 23:47