-1

I committed some changes which I directly uploaded to Github earlier today. Now while trying to push new changes, via the terminal, I get the following error:

 ! [rejected]        gh-pages -> gh-pages (fetch first)
error: failed to push some refs to 'https://github.com/cutiepie.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.

Please assist

LightCC
  • 9,804
  • 5
  • 52
  • 92
Loreen
  • 115
  • 1
  • 1
  • 7
  • 2
    Did you attempt the steps given in the error message? It says, "You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again." If you already tried it, what results and/or error messages did you receive? – nanofarad Jul 08 '20 at 20:06
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+remote+contains+work+that+you+do – phd Jul 09 '20 at 06:06

3 Answers3

0

Do a git pull origin, if same files modified you'd need to fix those merge conflicts. Otherwise do git commit and git push.

Mrinal Roy
  • 969
  • 7
  • 12
0
git pull origin <branch_name>

or

git pull origin <branch_name> --allow-unrelated-histories

then

git push origin <branch_name>

now you can push your local repository to the remote repository. you have to merge those new initialized files with your work. git push fetches and merges for you.

Nafaz M N M
  • 1,558
  • 2
  • 27
  • 41
0

After you pushed your earlier commit, it appears that someone else pushed one or more commits after yours, to the same branch. There are now two versions of the branch, and that needs to be resolved before git will allow you to complete a normal push.

The hint: lines in the error message explain this pretty well, along with where to find more information. I recommend following the instructions in the hint to and reading through the recommended section of the git help to fully understand what is going on.

A brief explanation

A change was pushed to the branch you are working on with new changes that are not in your local repo. Meanwhile, you have made new changes in the same branch that are not in the remote repo. So there are two versions of the same branch. Before you can push to the remote, Git needs you to resolve any differences between these two versions of the branch.

The most common way of doing this is to use git pull, which is basically a git fetch of the new remote commits, coupled with a git merge to merge the remote changes into your local changes, leaving you with a new merged commit locally that can then be pushed back out to the remote. The process should complete okay as long as you complete the merge and push back up before any more new commits are pushed from another user to the same branch on the remote.

LightCC
  • 9,804
  • 5
  • 52
  • 92