Git pull -The following untracked working tree files would be overwritten by merge
Asked Answered
S

3

8

I am trying to do git pull in master branch and I see this message with a long list of files

The following untracked working tree files would be overwritten by merge:

I really don't care if these files are over written or not, as I need to get the latest form remote. I have looked into it and I cannot do git fetch, git add * and git reset HARD

When I do git status, it shows me the list of only untracked files. I don't want to commit these files

Shane answered 6/4, 2016 at 17:18 Comment(4)
Are you sure these files aren't part of the git repository from which you are pull-ing? I've gotten this message when I have test.4gl uncommitted in one directory, and have it as part of the git repository from which I'm pulling. I could easily have misinterpreted what is going on, because I've only been using git for a year.Fideliafidelio
These files are the part of my git repo but I want them to be over written in masterShane
I just updated my answer.Fideliafidelio
Related posts - The following untracked working tree files would be overwritten by merge, but I don't care & How do I force “git pull” to overwrite local files?Sf
B
9

you may delete the untracked files before getting a pull from remote

git clean -f

add the flag n to see a dry run of the files that would be deleted.

git clean -f -n
Boris answered 6/4, 2016 at 17:26 Comment(1)
Tried this but again seeing the same error message on git pullShane
F
2

I just conducted a test to see what produces this error.

1) I created test.txt in my master git development directory, and added it to git.

2) I created test.txt as an untracked file in the git directory on our production system. From development (master branch) I usually push to a bare git repository remote, and on the development system (master branch) pull from the same bare git repository.

3) I got your error:

[ics@bucky ics_client]$ git pull origin
gituser@h2oamr's password: 
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From h2oamr:ics_client
   193ac65..a6da6b2  master     -> origin/master
Updating 193ac65..a6da6b2
error: Untracked working tree file 'test.txt' would be overwritten by merge.  Aborting
[ics@bucky ics_client]$ 

You could move these files away to a safe place, but be very careful after performing the pull. If you move the untracked files you previously moved back to your git directory, you'll overwrite what came over.

You could also add these files to git and then pull.

Or, you can delete these same files from the git repository from which you're pulling, not something I would do.

Responding to your comment

These files are the part of my git repo but I want them to be over written in master – baig772

and because I am not completely comfortable with git, I would ftp these to your master directory and update these files there. You probably could also do this, by moving these files to a safe place, bringing them back after the pull, and then updating from the satellite git directory, and pulling from the satellite git repository into the master directory.

Personally, I would do it the long way -- take changed files to master directory -- update there, and re-pull into satellite.

Fideliafidelio answered 6/4, 2016 at 17:37 Comment(0)
M
1

Please try with this command. git clean -f -d

Mckie answered 9/2, 2023 at 19:19 Comment(1)
With literally no explanation? Even if it works, this isn't helpful.Demonstrate

© 2022 - 2024 — McMap. All rights reserved.