I am trying to pull a project from GitHub, which I am collaborating on, but I receive the following error:
your local changes to the following files would be overwritten by
merge
I have tried to merge by:
git mergetool {pathtofile}
But it just respons with “File does not need merging”.
If I try to push my changes first I receive:
To prevent you from losing history, non-fast-forward updates were rejected.
What might I be missing?
You quote the following error moessage in your question:
This error message is essentially saying that git is stopping you from potentially losing work. You have some changes in your working tree that you haven’t committed yet, and the pull would modify those files – this might end up with you losing your local changes. Once you’ve committed your changes to those files, the pull will work. (Or, you could skip the “fetch” stage of
git pulland just rungit merge origin/masterto try the merge stage again.) Martin Ogden’s answer gives an example of usinggit stashas an alternative, which is more suitable if you’re not ready to commit your work yet.The latter error message is:
Basically, you’re only allowed to push if the commit you’re pushing already contains the history of branch you’re pushing to. The usual solution is to pull first. This is another error message that is preventing you from losing work – you wouldn’t (in general) want to wipe out the work that other people have pushed to that branch.