1

I just tried to commit something with this command:

git commit file_name
push origin reponame develop

and I got and error:

error: failed to push some refs to 'https://my_repo_path'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

so then I tried to do

git pull origin repo_name

and it gave me an error that:

* branch            develop    -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
    ... 3 file_names
Please, commit your changes or stash them before you can merge.

What is the common way to resolve this?

Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284

2 Answers2

4

It sounds like you have files that you modified but didn't commit. Try stashing your changes first, and then re-apply them on top of the head:

git stash
git pull origin repo_name
git stash pop
hexedpackets
  • 854
  • 10
  • 16
  • thank you - will this end up overwriting the changes the other developer made? What will be the consequences? – Genadinik Jan 29 '13 at 18:06
  • Should the --rebase option be used, or is it not needed? – DrC Jan 29 '13 at 18:07
  • --rebase will cause all of your changes to be based on a different part of the branch. It is dangerous to use in branches that have multiple people working on them. There's a really good explanation at http://stackoverflow.com/questions/457927/git-workflow-and-rebase-vs-merge-questions. – hexedpackets Jan 29 '13 at 18:09
  • @Genadinik It is similar to doing a local merge. Your changes will be applied on top of what the other developer did, but only locally until you commit them. Any merge conflicts will still have to be resolved. – hexedpackets Jan 29 '13 at 18:12
  • @William Huba Actually I got this error after doing the second line of your suggestion. CONFLICT (content): Merge conflict in BusinessPlan.xcodeproj/project.pbxproj Automatic merge failed; fix conflicts and then commit the result. – Genadinik Jan 29 '13 at 18:34
  • @Genadinik The pull attempted to merge the HEAD of the remote branch with your local commit but there was a conflict that couldn't be auto resolved. `git status` will show you the conflict, and you can re-commit after resolving it. Read up on resolving merge conflicts in the Git manual: http://www.kernel.org/pub/software/scm/git/docs/v1.7.3/user-manual.html#resolving-a-merge. – hexedpackets Jan 29 '13 at 19:31
2

You need to clean up your workspace before trying your pull. Do a git status and you'll see you have local, not-checked-in changes. You need to commit or stash those (like the message says) before you can update from your remote.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469