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.

You are watching: The following untracked working tree files would be overwritten by checkout:

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?

askedDec 27, 2019alecxe7.5k points

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 stashgit pullAfter 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.

answeredDec 27, 2019AbhijitJ38.6k points
ask related questioncomment

Your comment on this answer:

Your name to display (optional):
Email me at this address if a comment is added after mine:Email me if a comment is added after mine

Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

What is the color of the sky?
To avoid this verification in future, please log in or register.
Add commentCancel

0 votes


The problem is that you are not folowingthe files locally howeveridentical files are follwedremotely 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 stashgit pullThis will followall files, dispelall of your local changes to those files, and then findthe files from the server.

You can attemptcommand 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-dcan be replaced with the following:

-xignored files are also dispelas well as files unknown to Git.

-ddispeluntracked directories in addition to untracked files.

-fis necessaryto force it to run.

The only commands that performedfor me were:

git fetch --allgit reset --hard origin/{{your branch name}}A replacement forgit mergethat will overwrite unfollwedfiles

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

subsist in the donor branch,

do not exist in the takingbranch,

and are blocking the merge causethey are present and untracked in your working directory.

git checkout -f donor-branch # replace FOI with tracked `donor` versionsgit checkout receiving-branch # FOI are not in `receiving`, so they disapppeargit merge donor-branch # now the merge worksA replacement forgit pullthat will overwrite unfollwedfiles

pull = fetch + merge, hencewe dogit fetchfollowed by thegit checkout -f, git checkout, git mergetrick above.

git fetch origin # fetch remote commitsgit checkout -f origin/mybranch # replace FOI with tracked upstream versionsgit checkout mybranch # FOI are not in mybranch, so they disapppeargit merge origin/mybranch # Now the merge works. fetch + merge completes the pull.Elaborated explanation

git merge -fdoes not exist, butgit checkout -fdoes.

We will employgit checkout -f+git checkoutto dispelthe Files Of Interest , and then your merge can passnormally.

Step 1.This step perforcereplaces 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-branchStep 2.This step dispelsthe FOI causethey they are tracked in our current (donor) branch, and inexistentin thereceiving-branchwe switch to.

See more: Eat I Ate A Bowl Of Nails For Breakfast (Without Any Milk), Welcome To The Salty Spitoon

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