Fixing βYour local changes would be overwritten by mergeβ
You run git pull, expecting a quiet update, and Git throws this at you instead:
git pull origin master
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 14 (delta 8), reused 14 (delta 8), pack-reused 0
Unpacking objects: 100% (14/14), done.
From github.com:user/repo
* branch master -> FETCH_HEAD
953146e..9f38420 master -> origin/master
error: Your local changes to the following files would be overwritten by merge:
List of your local files ...
That error means you have uncommitted changes in your working directory that clash with what you are about to pull in. Here is why Git stops you, three ways to fix it, and the one command I actually use.
Why Git Blocks the Pull: Uncommitted Local Changes
git pull runs git fetch and then, by default, merges the fetched branch into your current one β that is documented behaviour, not an implementation detail. A merge has to combine changes from both branches, and if your uncommitted edits touch the same lines as the incoming commits, Git cannot work out which version you want. Rather than guess, it stops and shows you the error instead of quietly overwriting your work.
Solutions: How to Keep Local Changes During git pull, Without Losing Your Work
π Subscribe to keep reading.
Final thoughts
π Subscribe to keep reading.
References
π Subscribe to keep reading.
Subscribe to unlock the full article β€οΈ
Log in to unlock
The form below signs you up for the newsletter. It does not log you into the app β log in afterwards (same email) to unlock this article and download your subscriber gifts. New subscribers get an inbox mail: Set a password to unlock articles.
Full content temporarily unavailable β refresh in a moment