Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull aborts itself, local file changes will be overwritten by merge

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?

like image 303
Sasha_8 Avatar asked Aug 28 '13 11:08

Sasha_8


People also ask

Does git pull overwrite local changes?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.

Does git pull merge or overwrite?

git pull --force it feels like it would help to overwrite local changes. instead, it fetches forcefully but does not merge forcefully ( git pull --force = git fetch --force + git merge ). Like git push, git fetch allows us to specify which local and remote branch we want to work on.

How do you solve your local changes to the following files would be overwritten by merge?

The “Your local changes to the following files would be overwritten by merge” error occurs when you try to pull a remote repository to your local machine whose contents conflict with the contents of your local version of the repository. To fix this error, either stash your changes away for later or commit your changes.


1 Answers

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}
like image 97
nyzm Avatar answered Sep 28 '22 11:09

nyzm