• Register
0 votes
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 error :

“The following untracked working tree files would be overwritten by merge”

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

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

You can try the command to clear your untracked files from your local

Git 2.11 and newer versions as below:

git clean  -d  -f .

Older versions of Git as below :

git clean  -d  -f ""

Where -d can be replaced with the below options:

· -x ignored files are also removed as well as the files unknown to Git are also removed.

· -d removed the untracked directories in addition to untracked the files.

· -f is necessary to force it to run.

OR

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

Try running below commands :

git add * 
git stash
git pull

This will solve your issue.

9 7 4
38,600 points
0 votes

Solution:

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

Follow this code

git add * 
git stash
git pull

This will track all files, remove all of your local changes to those files, and then get the files from the server.

You can try 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 removed as well as files unknown to Git.

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

  • -f is required to force it to run.

A replacement for git pull that will overwrite untracked files

pull = fetch + merge, so 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.

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 15 views
15 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 9 views
9 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
1 vote
2 answers 2.4K views
2.4K 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 ... 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?
asked Dec 27, 2019 alecxe 7.5k points
0 votes
1 answer 243 views
243 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 2 views
2 views
Problem: anyone who know this problem please help? untracked working tree file would be overwritten by merge
asked Mar 30 Rohit kr 16.2k points
0 votes
1 answer 162 views
162 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 287 views
287 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 9 views
9 views
Problem: your local changes to the following files would be overwritten by merge
asked Mar 4 ummesalma 25.2k points
0 votes
1 answer 79 views
79 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