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

24,338

Solution 1

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

Solution 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.

Share:
24,338
baig772
Author by

baig772

For the past 12+ years, I have been working in the industry, leading the way into what are now well-known technologies. For the past 6 years, I have been building and heading a team focused on Agile Development Practices using the Accelerate Strategies, as well as modern technologies and workflows such as Laravel, AWS ECS, AWS Serverless. Lambda, Elastic Search, ReactJS, VueJS, Continuous Integration and Deployment and more. During those years, I have led numerous releases of projects with teams ranging from just me to 20+ people. My most recent work has allowed the team to perform at elite levels. Each project pushes the technology stack we use, the skills of the team, and the possibilities of the Web Applications that we can create.

Updated on June 03, 2021

Comments

  • baig772
    baig772 almost 3 years

    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

  • baig772
    baig772 about 8 years
    Tried this but again seeing the same error message on git pull