• Register
1 vote

Problem  :

On the branch which I had some of my files in .gitignore

On the different branch those files are not present.

So I want to merge the different branch into my branch and I really do not care about those files if they are no longer ignored or not.

But I am facing below error:

The following untracked working tree files would be overwritten by merge

How can I modify the pull command to overwrite the files, without me needing to find, move or delete the files by myself?

7.5k points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I had the same issue and tried all the solutions which I knew, and neither of them worked actually after long research I found the solution for the error as below:

The problem with your branch is that you are not tracking your files locally but the identical files are getting tracked remotely so in order to be able to "pull" the system need to be forced to overwrite your local files which are not the version controlled.

So try running below commands :

git add * 
git stash
git pull

After executing all above commands it will track all your files and remove all of your local changes to those files and after that it will get the files from your server.

38.6k points
0 votes


The problem is that you are not folowing the files locally however identical files are follwed remotely so in order to "pull" your system would be forced to overwrite the local files which are not version controlled.

Attempt running

git add * 
git stash
git pull

This will follow all files, dispel all of your local changes to those files, and then find the files from the server.

You can attempt command to clear the untracked files from the local

Git 2.11 and newer versions:

git clean  -d  -f .

Older versions of Git:

git clean  -d  -f ""

Where -d can be replaced with the following:

  • -x ignored files are also dispel as well as files unknown to Git.

  • -d dispel untracked directories in addition to untracked files.

  • -f is necessary to force it to run.

The only commands that performed for me were:

git fetch --all
git reset --hard origin/{{your branch name}}

A replacement for git merge that will overwrite unfollwed files

The comments below conduct 'FOI' for the 'files of interest', the files that

  • subsist in the donor branch,

  • do not exist in the taking branch,

  • and are blocking the merge cause they are present and untracked in your working directory.

git checkout -f donor-branch   # replace FOI with tracked `donor` versions
git checkout receiving-branch  # FOI are not in `receiving`, so they disapppear
git merge donor-branch  # now the merge works

A replacement for git pull that will overwrite unfollwed files

pull = fetch + merge, hence we do git fetch followed by the git checkout -f, git checkout, git merge trick above.

git fetch origin  # fetch remote commits
git checkout -f origin/mybranch  # replace FOI with tracked upstream versions
git checkout mybranch  # FOI are not in mybranch, so they disapppear
git merge origin/mybranch  # Now the merge works. fetch + merge completes the pull.

Elaborated explanation

git merge -f does not exist, but git checkout -f does.

We will employ git checkout -f + git checkout to dispel the Files Of Interest , and then your merge can pass normally.

Step 1. This step perforce replaces untracked FOI with tracked versions of the donor branch (it also checks out the donor branch, and updates the rest of the working dir).

git checkout -f donor-branch

Step 2. This step dispels the FOI cause they they are tracked in our current (donor) branch, and inexistent in the receiving-branch we switch to.

git checkout receiving-branch

Step 3. Now that the FOI are inesixtent, merging in the donor branch will not overwrite any untracked files, so we get no errors.

git merge donor-branch

Dispel all untracked files:

git clean  -d  -fx .


31.1k points
edited by