Git - Won't add files?

Solution 1:

I found myself in a similar situation as the poster:

If I call "git add .", and then "git status" and it keeps saying "working directory clean" and has nothing to commit.

But I had a different solution than what's here. Since I came to this first, I hope to save others some time.

From the above answers and what I've seen elsewhere, the usual fixes to this problem are:

  • Ensure there are actually saved changes on the file in question
  • Ensure the file doesn't meet your exclude rules in .gitignore and .git/info/exclude
  • Ensure you're not trying to add an empty folder. Git won't track those. Standard solution is to place a blank file named .gitkeep as a placeholder so git will track the folder.

In my case, I had originally tried to create a git repo around an existing repo (not knowing it was there). I had removed the .git folder from this sub repo a while ago, but I didn't realize that it was too late, and git was already tracking it as a submodule. You can read more about how these behave and how to remove them here, but

  • the solution for me was to simply run git rm --cached path_to_submodule.

Solution 2:

To add to the possible solutions for other users:

Make sure you have not changed the case of the folder name in Windows:

I had a similar problem where a folder called Setup controlled by Git and hosted on GitHub, all development was done on a Windows machine.

At some point I changed the folder to setup (lower case S). From that point on when I added new files to the setup folder they were stored in the setup folder and not the Setup folder, but I guess because I was developing on a Windows machine the existing Setup folder in git/github was not changed to setup.

The result was that I couldn't see all of the files in the setup in GitHub. I suspect that if I cloned the project on a *nix machine I would have seen two folders, Setup and setup.

So make sure you have not changed the case of the containing folder on a Windows machine, if you have then I'd suggest:

  • Renaming the folder to something like setup-temp
  • git add -A
  • git commit -m "Whatever"
  • Rename the folder back to what you want
  • git add -A
  • git commit -m "Whatever"

Solution 3:

If the file is excluded by .gitignore and you want to add it anyway, you can force it with:

git add -f path/to/file.ext

Solution 4:

Odd, but I fought with git all night to add a file. Turns out it was already added. Git wasn't picking up my changes, as the changes weren't being saved, as the file was inaccessible by my account, and my IDE wasn't reporting this over SSH.

In short, check to make sure you don't have it already added to the repository.

Solution 5:

Double check your .gitignore file to make sure that the file is able to be seen by Git. Likewise, there is a file .git/info/exclude that 'excludes' files/directories from the project, just like a .gitignore file would.