Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 897
baig772 Avatar asked Apr 06 '16 17:04

baig772


2 Answers

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
like image 80
Mathews Avatar answered Oct 13 '22 03:10

Mathews


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.

like image 23
octopusgrabbus Avatar answered Oct 13 '22 05:10

octopusgrabbus