Skip to main content

Explore your training options in 10 minutes

Error: the Following Untracked Working Tree Files Would Be Overwritten by Merge

Kelly M. - November 10, 2020

The error above is often triggered when we do not clone the repository we are trying to pull from. The projects may be identical, but we may be working on one locally while trying to pull it from the repo on Github because it may have other files or features we’d like to incorporate on our local version.

There are several ways to fix this.

Tell the Local Branch to Track the Remote Branch

We can do this by using the command below.

Get offers and scholarships from top coding schools illustration

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses

By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

git branch --track <branch-name> origin/<branch-name>

By doing this, the remote branch becomes a counterpart to the remote server. After this, do a git status to see the difference between the two repos.

Staging and Stashing

To pull so local files are not overwritten from version control, we can also stage and then stash by using the commands below.

git add -A 
git stash
git pull

With git add -A, we are staging all changes. It is the same as git add in that it looks at all

working trees and adds all working paths to stages changes, changed, new, or not ignored. In addition to this, it also acts like git add -u in that it looks at the files already being tracked, and stages the changes to those files if they have been removed or if they differ.

With git stash we are taking staged and unstaged uncommitted changes, stashing them away for future use, then reverting them from a working copy. After this, we are free to make changes like pulling new files.

Fetching and Resetting

If neither of the above has worked for you yet, try fetching and resetting. Because we will be using –hard on this option, it is important to at least attempt the two above as –hard is a potentially dangerous command which throws away all uncommitted changes.

Please do a git status before attempting the fix below to make sure your output is empty.

git fetch --all
git reset --hard origin/<branch-name>

With git fetch –all, we can fetch all remote branches. Fetch will update local copies of remote branches, but will not update local branches that track remote branches. To achieve this, we need to do a git pull –all.

With git reset –hard origin/<branch-name>, we are essentially saying “throw everything away that is in my local branch, and make it the same as my remote branch”. It throws away all staged and unstaged changes.


The error: the following untracked working tree files would be overwritten by merge is triggered when we are trying to pull a remote branch while on a local one. The projects may be identical, but the local one needs to be able to track the remote for it to pull successfully.

This error is often triggered when the developer forgets to clone a repo. Other ways to fix this error is by staging and stashing or fetching and resetting, which should be attempted only if the first two methods were not successful.

Venus, a software engineer at Rockbot

"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"

Venus, Software Engineer at Rockbot

About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.

What's Next?

Kelly M.

About the author: Kelly is a technical writer at Career Karma, where she writes tutorials on a variety of topics. She attended the University of Central Florida, earning a BS in Business Administration. Shortly after, she attended Lambda School, specializing in full stack web development and computer science. Before joining Career Karma in September 2020, Kelly worked as a Developer Advocate at Dwolla and as a team lead at Lambda School. Her technical writing can be found on Codecademy, gitConnected, and JavaScript in Plain English.

Skip to main content