• 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?

6 5 3
7,540 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.

9 7 4
38,600 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 .


10 6 4
31,120 points

Related questions

0 votes
2 answers 3.2K views
Problem : On the branch I had some files in the .gitignore On the different branch those files are not. I am trying to merge the different branch into my branch, and I don't bother if those files are no longer overlooked or not. Unfortunately I get below ... by merge” How should I modify the pull command to overwrite those files, without needing to find, move or delete those files by myself?
asked Jan 6, 2020 alecxe 7.5k points
0 votes
1 answer 199 views
Problem : I added the folder to the .gitignore file. Once I do the git status it tells me # On branch latest nothing to commit (working directory clean) But when I try to change my branches I get the below: My-MacBook-Pro:webapp marcamillion$ git checkout develop ... /system/images/* public/system/avatars/* How do I get this working for me so I can switch my branches without deleting those files?
asked Jan 22, 2020 jwilliam 3.9k points
0 votes
1 answer 145 views
Problem : How can I ignore the below error message on the Git pull? Your local changes to the following files would be overwritten by merge What if I just want to overwrite them? I Have already tried many things like git pull -f, but nothing really works for me.To be very clear, I just want to overwrite the specific changes and not the everything.
asked Jan 2, 2020 alecxe 7.5k points
0 votes
2 answers 222 views
Problem : I have the project with two branches as staging and beta. I try to develop on staging, and use my master branch to fix the bugs. git checkout master And do the stuff on it : git add fileToAdd git commit -m "bug fixed ... be overwritten by checkout: src/Pro/ConvocationBundle/Controller/DefaultController.php Please, commit your changes or stash them before you can switch branches. Aborting
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 46 views
Problem: I have basic knowledge of GIT. Whenever I try to pull in my project directory in my terminal then I face the below error: /Sites/branch1$ git pull origin master U app/config/app.php U app/config/database.php U app/routes.php Pull is not possible because you have ... 'git commit -a'. Why does my git is showing me above error? and how can a beginner like me fix above git pull error?
asked Aug 27, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 5 views
Problem : Error: you need to resolve your current index first
asked 4 days ago Shovo210 2.9k points
0 votes
1 answer 9 views
Problem: Git:nothing added to commit but untracked files present
asked 5 days ago Shovo210 2.9k points