How to merge remote changes at GitHub?

GitGithub

Git Problem Overview


I'm getting following error, whn trying first Github push:

[rejected] master -> master (non-fast forward)
error: failed to push some refs to '[email protected]:me/me.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.

how can I fix this and merge remote changes?

Git Solutions


Solution 1 - Git

See the 'non-fast forward' section of 'git push --help' for details.

> You can perform "git pull", resolve potential conflicts, and "git push" the result. A "git pull" will create a merge commit C between commits A and B.

> Alternatively, you can rebase your change between X and B on top of A, with "git pull --rebase", and push the result back. The rebase will create a new commit D that builds the change between X and B on top of A.

Solution 2 - Git

You can also force a push by adding the + symbol before your branch name.

git push origin +some_branch

Solution 3 - Git

You probably have changes on github that you never merged. Try git pull to fetch and merge the changes, then you should be able to push. Sorry if I misunderstood your question.

Solution 4 - Git

If you "git pull" and it says "Already up-to-date.", and still get this error, it might be because one of your other branches isn't up to date. Try switching to another branch and making sure that one is also up-to-date before trying to "git push" again:

Switch to branch "foo" and update it:

$ git checkout foo
$ git pull

You can see the branches you've got by issuing command:

$ git branch

Solution 5 - Git

You can force it to push, but please do this ONLY when you're quite sure what you are doing.

The command is:

git push -f 

Solution 6 - Git

This problem can also occur when you have conflicting tags. If your local version and remote version use same tag name for different commits, you can end up here.

You can solve it my deleting the local tag:

$ git tag --delete foo_tag

Solution 7 - Git

When I got this error, I backed up my entire project folder. Then I did something like

$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master

...depending on your branch name (if it's not master).

Then I did git pull --rebase. After that, I replaced the pulled files with my backed-up project's files. Now I am ready to commit my changes again and push.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn View Question on Stackoverflow
Solution 1 - GitThiloView Answer on Stackoverflow
Solution 2 - GitSammyKView Answer on Stackoverflow
Solution 3 - GitJorge Israel PeñaView Answer on Stackoverflow
Solution 4 - GitDavid CalhounView Answer on Stackoverflow
Solution 5 - GitJuLyView Answer on Stackoverflow
Solution 6 - GitZdsView Answer on Stackoverflow
Solution 7 - GitIgorGanapolskyView Answer on Stackoverflow