Elena' s AI Blog

Preserve your local changes on Git Pull

02 Aug 2023 (updated: 17 Aug 2026) / 7 minutes to read

Elena Daehnhardt


Jasper AI-generated art, January 2023


TL;DR:
  • Solutions for Git pull errors when local changes would be overwritten: preserving uncommitted changes with stash, commit, or discard before merging, or in one go with git pull --rebase --autostash.

Previous: Part 10 β€” Restoring deleted files in Git

Next: Part 12 β€” Git Failed to Push Some Refs

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 ❀️

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.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2023) 'Preserve your local changes on Git Pull', daehnhardt.com, 02 August 2023. Available at: https://daehnhardt.com/blog/2023/08/02/preserve-your-local-changes-on-git-pull/
All Posts