Git pull error Entry foo not uptodate. Cannot merge
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If you have ever run git pull and been greeted with the error "Entry 'foo' not uptodate. Cannot merge.", you know how frustrating it can be when Git refuses to cooperate. This error occurs because Git is protecting you from losing uncommitted local changes that overlap with incoming changes from the remote. Understanding why Git raises this guard and how to resolve it will save you time and prevent accidental data loss.
Why This Error Happens
To understand the root cause, you need to know how Git tracks file states across three layers. The working tree is your actual files on disk. The index (also called the staging area) holds the snapshot you are preparing for the next commit. HEAD points to the last commit on your current branch. When you run git pull, Git performs a fetch followed by a merge. The merge step needs to combine the remote changes with your local HEAD, but it also checks whether your working tree and index are clean. If Git detects that a file has been modified locally but not committed, and that same file was changed in the incoming commits, it refuses to merge because it cannot safely combine the two versions without risking data loss.
The asterisk indicates that foo has uncommitted local modifications. Git sees a conflict between your local changes and the incoming version and halts the merge entirely.
Fix 1 — Stash, Pull, Then Pop
The most common fix is to temporarily shelve your local changes using git stash, perform the pull, and then reapply your changes on top.
If the reapply step produces conflicts, Git will mark the conflicting sections in the file with standard conflict markers (<<<<<<<, =======, >>>>>>>). Resolve them manually, then stage and commit the result. This approach is ideal when your local changes are work-in-progress that you want to keep.
Fix 2 — Commit Your Changes First
If your local modifications are ready to be saved, simply commit them before pulling. This gives Git two proper commits to merge.
After the pull, Git will attempt a merge between your commit and the remote changes. If both sides modified the same lines, you will get a merge conflict to resolve, but your work is safely recorded in a commit either way.
Fix 3 — Discard Local Changes
If you do not need your local modifications and just want the remote version, you can discard your changes entirely.
Be careful with this approach — git checkout -- foo permanently discards your local edits to that file. There is no undo. Only use this when you are certain the local changes are expendable.
Using git pull --rebase
An alternative to the default merge-based pull is git pull --rebase, which replays your local commits on top of the fetched remote commits instead of creating a merge commit. This keeps the history linear and cleaner.
The rebase approach is especially useful in teams that prefer a linear commit history. However, it still requires a clean working tree, so you must stash or commit local changes before running it.
Understanding the Three-Layer Model
A deeper understanding of the working tree, index, and HEAD helps prevent this error from recurring.
When git status shows modified files under "Changes not staged for commit", those are working tree changes that have not been added to the index. Files under "Changes to be staged for commit" are in the index but not yet committed. Both categories can trigger the "not uptodate" error if the same files are changed remotely.
Common Pitfalls
- Running
git checkout -- .to discard all changes wipes every modification in your working tree, not just the conflicting file. Always target specific files. - Forgetting to pop the stash after pulling leaves your work hidden in the stash stack. Use
git stash listto check for forgotten stashes. - Assuming
git pull --rebaseavoids all conflicts is incorrect. Rebase replays commits one at a time, and each replay can produce its own conflicts. - Not checking
git statusbefore pulling means you may not realize which files have local modifications, leading to surprise errors. - Stashing untracked files requires the
-uflag (git stash -u). Without it, new files that are not yet tracked by Git will not be stashed and may still block the pull.
Summary
- The "Entry not uptodate. Cannot merge" error means Git found uncommitted local changes that conflict with incoming remote changes.
- Use
git stashthengit pullthengit stash popto temporarily shelve and reapply your work. - Commit your local changes before pulling if they are ready to be saved.
- Use
git checkout -- <file>to discard local changes you do not need, but be aware this is permanent. - Use
git pull --rebasefor a linear history, but always start from a clean working tree. - Run
git statusandgit diffbefore pulling to understand exactly what local changes exist.
Related reading
- git pull error error remote ref is at but expected
- git pull fails unable to resolve reference unable to update local ref
- git pull fails unable to resolve reference unable to update local ref
- git pull while not in a git directory
- Git Push Error insufficient permission for adding an object to repository database
- Git Push Error insufficient permission for adding an object to repository database
- Git pulling a branch from another repository?
- git push --force-with-lease vs. --force
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.