Reputation: 347
I am trying to push new changes, but I have a conflicted file. After trying to push, I get the following error:
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
Ok, so we need to use git pull.
I try to use git pull
and then I get this error:
error: Your local changes to the following files would be overwritten by merge:
db/profile_edit.php
Please, commit your changes or stash them before you can merge.
But, when I try to commit, I go back to the first error. What should I do? The changes on the remote repo are newer than the ones on my local machine. So, how do I open it up with a diff tool and make the changes and then tell git that I have made changes so it will let me push changes?
Upvotes: 10
Views: 21426
Reputation: 31695
You're getting yourself confused with the commands.
git commit
saves changes into git's database
git pull
brings remote commits into your repo
You're trying to pull with uncommitted changes, so git is asking you to commit those first (or git stash
them away) so that it can merge your local changes with the remote ones.
Upvotes: 5
Reputation: 4062
Try to do
$ git pull --rebase
To pull remote changes before yours, and then commit. And see if it works.
If this does not work, try this instead:
$ git stash
$ git pull --rebase
$ git stash pop
To save your changes on the stash
, apply remote commits inside your work-repository, and then apply your changes (saved into stash
) inside your work-repository again.
Upvotes: 23
Reputation: 13907
First, I think if you were to git add
then git commit
, your local repo would be clean enough to do a git pull
.
However, if there may be changes you don't want to commit until you see what happened on the upstream, you can use git stash
. It will temporarily clean up your working directory and save your changes, so you can pull (I would recommend git pull --rebase
to avoid merge points - but it is a personal taste issue). Once you have upstream changes pulled, you can get your local modifications back using git stash pop
. After you clean up conflicts and get rid of unnecessary changes, you can add, commit, then finally push.
Upvotes: 8