Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you git fetch then merge? "Error: Your local changes to the following files would be overwritten by merge"

Tags:

Newbie Git question: I have a repo set up on bitbucket. I git fetched someone else's changes and would like to merge them with my own. However, when I try to git merge (or git merge origin/master), I get the message "error: Your local changes to the following files would be overwritten by merge:", and then a list of files I've changed. Having Git merge these changes is exactly what I want to do though.

like image 930
ario Avatar asked Mar 06 '12 16:03

ario


People also ask

How do you fix git error your local changes to the following files will 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.

Will git fetch overwrite local changes?

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


2 Answers

You can either commit your changes before you do the merge, or you stash them:

git stash git merge origin/master git stash pop 
like image 54
ralphtheninja Avatar answered Oct 12 '22 10:10

ralphtheninja


If you want to keep your changes, you can commit your changes to your local repository first and then merge the remote repository.

like image 26
mamills Avatar answered Oct 12 '22 10:10

mamills