• Register
1 vote
2.6k views

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

Solution:

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
1 answer 29 views
29 views
Problem: Urgent problem, any help: Error: the following untracked working tree files would be overwritten by merge:
asked Mar 13 Wafa Abu Yousef 6.1k points
0 votes
1 answer 13 views
13 views
Problem: did anyone face this situation ! help : Error: the following untracked working tree files would be overwritten by merge.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
2 answers 3.5K views
3.5K 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 10 views
10 views
Problem: HELP! I need help understanding this error > Git the following untracked working tree files would be overwritten by merge
asked Apr 30 ummeshani 9.5k points
0 votes
1 answer 5 views
5 views
Problem: Why I get this > Git the following untracked working tree files would be overwritten by checkout
asked Apr 28 ummeshani 9.5k points
0 votes
1 answer 6 views
6 views
Problem: I added a folder to my .gitignore file. Once I do a git status it tells me # On branch latest nothing to commit (working directory clean) However, when I try to change branches I get the following: My-MacBook-Pro:webapp marcamillion$ git checkout develop error: The ... would everything be perfect as up to my latest commit? I don't want to lose those files, I just don't want them tracked.
asked Apr 26 sumaiya simi 43.9k points
0 votes
1 answer 4 views
4 views
Problem: So I added a folder to my .gitignore file. Once I do a git status it tells me # On branch latest nothing to commit (working directory clean) However, this is what my .gitignore file looks like: .bundle .DS_Store db/*.sqlite3 log/*.log tmp/**/* public/ ... afterwards would everything be perfect as up to my latest commit? I don't want to lose those files, I just don't want them tracked.
asked Apr 30 muktaa 34.6k points
0 votes
1 answer 272 views
272 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 5 views
5 views
Problem: anyone who know this problem please help? untracked working tree file would be overwritten by merge
asked Mar 30 Rohit kr 17.5k points