16

I have a git repository on a mac, when I use git status in terminal it says

On branch master
nothing to commit, working directory clean

when I try to pull changes from repository git pull repositoryName master

error: The following untracked working tree files would be overwritten by merge:
.DS_Store
Please move or remove them before you can merge.

so I tried to remove it with git rm .DS_Store but it says

fatal: pathspec '.DS_Store' did not match any files

I then tried to remove the cached file and add it again with git rm --cached . -r and git add . with a .gitignore directive that would ignore .DS_Store but the problem still persists.

I tried lots of commands that I saw on different posts without success. Any help would be appreciated.

jvarela
  • 3,744
  • 1
  • 22
  • 43
D4rWiNS
  • 2,585
  • 5
  • 32
  • 54

4 Answers4

13
rm .DS_Store

I ran the above command on the repo folder. and finally could pull from git. I suggest you add .DS_Store in your .gitignore file.

Ares
  • 2,504
  • 19
  • 19
  • Problem is if you add a `.gitignore` you see a new issue: `error: Your local changes to the following files would be overwritten by checkout: .gitignore` – bobobobo Dec 19 '20 at 23:29
  • So commit your change on `.gitignore` and push to the git. – Ares Jan 07 '21 at 03:10
10

.DS_Store

is a Mac related file that is created every time you touch some directory (if I'm not mistaken, it is used for indexing).

So, first you don't have it. Then you try to bring some files/folders into your directory (and thus it gets created - breaking your pull command).

In your repo directory create a file called .gitignore and inside it have a single line (so far) .DS_Store. This should fix your problem.

jvarela
  • 3,744
  • 1
  • 22
  • 43
Eugene
  • 117,005
  • 15
  • 201
  • 306
  • 1
    even after adding it to gitignore, still I'm getting the same error – David Johns May 04 '20 at 05:07
  • make sure you delete the .DS_Store file also from the repository. The git error message comes from the fact that the conflicting file is in your directory (created by Finder while navigating/changing view settings/sorting) and git wants to overwrite it with the one in the repository. – pd95 Jun 19 '20 at 06:58
3

I solved it by deleting .DS_Store from the git origin repository.

jvarela
  • 3,744
  • 1
  • 22
  • 43
1

When you mkdir your folder, you can enter this command git init and then pull. That will solve your problem.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135