[git] Git - Won't add files?

I'm having issues where I can't add files to my repository.

I'm using GIT on windows, in Aptana Studio for some Ruby development.

I've managed to push a few files up to GitHub, but then after this, everything's stopped working. I have for example a new sub-folder in my master directory, with 2 ruby files inside. If I call "git add .", and then "git status" and it keeps saying "working directory clean" and has nothing to commit.

I've tried "git add folder/myfile.rb" and still nothing.

Anyone any idea's what I can try?

This question is related to git

The answer is


Similar happened for me when I renamed a file between Uppercase/Lowercase. So, temporary file renaming might fix problem.


Silly solution from me, but I thought that it wasn't adding and pushing new files because github.com wasn't showing the files I had just pushed. I had forgotten that the files I added were on a different branch. The files had push just fine. I had to switch from my master branch to the new branch in github to see them. Lost a few minutes on that one :)


I have tried all the above but nothing was working. Later on, I ran my command prompt as an admin and retried all the stages i.e. staging-> committing-> remote add -> pushing. It worked like a magic. The changes were reflected in the desired remote repository.


I think if you logout of the previous project in git bash and then try to add those files to the new project. It will work fine


Had the same issue with a repo that I cloned from SiteGround Git to my mac. The freshly cloned repo had a list of changed files that git status said needed to be added to the commit, but trying to add or checkout any of them didn't do anything at all.

For some reason there were case changes in the filenames (e.g. .jpg -> .JPG). The solution was to simply git mv the filename the OS was using to the name git was using, e.g.:

git mv File_That_Wont_Add.txt File_THAT_WONT_Add.txt

Here is how I got mine to work:

I started by

git init 

inside the directory with all the files/folders that I wanted to include.

I ran

git add --all
git add .
git commit -m "uploaded fixed sources 3"
git push origin master

THEN

I made another directory outside of the origin, I moved into that directory, then I cloned the existing git repo using the http://../../.git file as set out on the page in github.

Once it cloned the source (which had nothing more than a readme.md) I copied all the files from the old directory into the new one with

cp -rf ../../* .

Then I added again, and then commited and pushed those edits.

git add --all
git add .
git commit -m "uploaded fixed sources 4"
git push origin master

Don't ask me why, but this time they uploaded into the github site and appeared as files you can access in the .zip tarball.


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.

Best bet is to copy your folder. Delete the original. Clone the project from github, copy your new files into the new cloned folder, and then try again.


You can remove recursively the git initialised repo $cd repo added $git rm -rf git

You can create a separate branch and link the submodules to the master branch The documentation on submodules is really useful Documentation [https://git-scm.com/book/en/v2/Git-Tools-Submodules]

Also see some solutions in [https://stackoverflow.com/questions/36236484/maintaining-a-git-repo-inside-another-git-repo]


I recently experienced this issue on my computer running Windows 7. I am using the git command window interface. The solution was to be very careful about the case sensitivity of the file and directory names when doing the git add. Although git would not complain when the case did not exactly match the case of the Windows file system file and directory names it also would not add the files. There would be nothing to commit. Once I typed the file names with the exactly correct case they would be added and listed under the changes to be committed as I intended.


How about the standard procedure:

git add folder
git commit

This will add the folder and all it's files with a single command.
Please note, git is not able to store empty folders.

If commit didn't worked, the first place you should check is probably .gitignore.


I had a problem where files from one folder wont get added to the Github source control. To solve that I deleted the .git folder that was created under that folder.


I had this problem with the first program in the folder. I did "git add" then "git commit". "git status" gave the error described i.e. "nothing to commit, working directory clean"

I ended up deleting the .git file from the program folder. Then I did a new git init, git add and git commit and it worked.


In my case the issue was enabled SafeCrLf option. I am on windows with tortoise git. After disabling the option adding the files was not an issue anymore.


Here you can find an answer to the same problem:

basically in this case the problem was the global_git ignore


I was having this issue on Visual Studio, what worked for me was: 1- Right click on the added file that is not being recognized by git. 2- Select "Add excluded file to Source Control"


Issue git would not add a changed file. Using git bash, I had changed folder delimiting the folder name with the double quote. ls displayed the folder contents correctly but git would not add changed files.

Solution I used the single quote to delimit the folder name.

e.g. CD "Folder Name" git status nothing to commit, working tree clean CD .. ls 'Folder Name' CD 'Folder Name' git status modified: ModifiedFileName.bat


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"

It's impossible (for me) to add the first file to an empty repository cloned from GitHub. You need to follow the link README, that GitHub suggests to create. After you create your first file online, you can work normally with git.

This happened to me Nov 17, 2016.


I know this is a really old question, but I know it can happen to someone as well, turns out I was working with a file named AUX.JS and thi is a reserved file name for windows, this produced the following error

fatal: unable to stat 'src/hoc/Aux.js': No such file or directory

so you can either remove the file or rename it, then it will work.

Final conclusion, in addition to all other valid answers, if you are in a windows machine look out for the output of the 'git add' command, it can also provide additional information.


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.


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.


I just had this issue and the problem was that I was inside a directory and not at the top level. Once I moved to the top level it worked.


I am still a beginner at git, and it was just a stupid mistake I made, long story in one sentence. I was not in a subfolder as @gaoagong reported, but the other way round, in a parent folder. Strange enough, I did not get the idea from that answer, instead, the idea came up when I tested git add --all, see the long story below.

Example in details. Actual repo:

enter image description here

The Parent folder that I had opened mistakenly on parent level (vscode_git in my case):

enter image description here

I had cloned a repo, but I had a parent folder above this repo which I had opened instead, and then I tried adding a file of the subfolder's repo with git add 'd:\Stack Overflow\vscode_git\vscode-java\.github\ISSUE_TEMPLATE.md', which simply did nothing, no warning message, and the git status afterwards said:

nothing added to commit but untracked files present (use "git add" to track)

enter image description here

Running git add --all gave me the yellow notes:

warning: adding embedded git repository: vscode-java the embedded repository and will not know how to obtain it.

hint: If you meant to add a submodule, use: git submodule add vscode-java

hint: If you added this path by mistake, you can remove it from the index with git rm --cached vscode-java

See "git help submodule" for more information.git

enter image description here

To fix this, I reverted the git add --all with git rm --cached -r -f -- "d:\Stack Overflow\vscode_git\vscode-java" rm 'vscode-java':

enter image description here

Then, by simply opening the actual repo folder instead,

enter image description here

the git worked as expected again. Of course the ".git" folder of the parent folder could be deleted then:

enter image description here


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

Another issue can be file permissions. Try issuing : chmod 755 file1


I searched around for a while and ended up finding out I had blocked off the SSH port which was what caused the git add command to stop working. I ended up changing origin using https with the following command: git remote set-url origin [url-to-git-repo]


I had the same problem and it was because there was a program using some file and git throws an error in this case Visual Studio had locked that file.


I had a similar issue.

The problem was, on Windows, in the index, the file was added in a case different from what was in the unstaged area. For example, in the index, the file was name xx.txt and in the unstaged area, the file was names Xx.txt.

Removed the file with the incorrect case from the index (xx.txt). Then, I have been able to add the file with the correct case (Xx.txt).


In such cases, please check for rules in global .gitignore file and make sure that your folder does not fit into those.