14

I have changed a file that my friend is working at the same time. I did some changes and now I want to push it but it says I should pull first. When I git pull, it says:

error: Your local changes to the following files would be overwritten by merge: Please, commit your changes or stash them before you can merge.
Aborting

How can I merge the file? If I do it would the file from my friend completely change? I am sure he has added some stuff and I have added my stuff. How will our changes be handled?

random
  • 9,774
  • 10
  • 66
  • 83
Sasha_8
  • 143
  • 1
  • 1
  • 8
  • possible duplicate of [How do I resolve git saying "Commit your changes or stash them before you can merge"?](http://stackoverflow.com/questions/15745045/how-do-i-resolve-git-saying-commit-your-changes-or-stash-them-before-you-can-me) – stdcall Aug 28 '13 at 17:20

2 Answers2

21

One approach is to commit that file first then pull.

git add filename
git commit 
//enter your commit message and save 
git pull 

Another approach is stash your changes then pull. Then apply stash.

git stash
git pull
git stash apply stash@{0}
nyzm
  • 2,787
  • 3
  • 24
  • 30
3

Do git commit and then git pull. It fetch your friend changes at first and then merge your changes, nothing will be lost.

Conflicts between your changes will be represented such way:

Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.

Or you could use some interactive merge tool.

Leonid Shvechikov
  • 3,927
  • 2
  • 17
  • 14