119

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?

4
  • It was some foolish mistake on my side, I'm using tortoise git and there is checkbox when you commit any changes, it was unchecked on my side and I have some new files locally only, so be careful with it!
    – BotanMan
    Jul 1, 2015 at 9:37
  • 2
    amazingly manojlds suggestion of restarting worked for me. one file was being excluded all of a sudden. after restart it magically worked Mar 3, 2021 at 3:41
  • My solution is open the file that youre trying to add to git and type something and remove whatever you typed (ie to mark it as edited) then save the file. then try to git add with force: git add -f <filename> Apr 12, 2022 at 19:45
  • LMAO my problem was that I had cd'd into a dir. Had to cd back to root dir to make git add . work. Mar 14, 2023 at 18:50

32 Answers 32

185

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.
4
  • 42
    Lifesaver! I simply had to type git rm --cached name_of_former_submodule and it got the path automatically.
    – leymannx
    Jun 17, 2014 at 13:03
  • 11
    what is submodule May 5, 2016 at 0:56
  • I think some files was never added but there had, so a git ls-files showed them and I understand why my git add doesn't had them
    – bcag2
    Feb 22, 2022 at 10:20
  • Since the question "what is submodule" continues to receive upvotes, I've updated the post to directly link to the git docs page on submodules. A basic answer would be "A submodule is a Git repository that is tracked as a subdirectory of another Git repository."
    – zrisher
    Jun 14, 2023 at 21:04
41

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"
6
  • 8
    This happened to me with a file name as well. Using git mv -f newFileCase oldFileCase will correct the repository Apr 11, 2016 at 14:40
  • 1
    I had a case issue on osx, unfortunately even though it is a *nux file system it is generally set up as case-insensitive which can cause issues with *nux tools like git.
    – Pellet
    Nov 1, 2016 at 7:34
  • Thanks, you saved my day
    – Zhenya
    Nov 1, 2017 at 16:09
  • if you have pending changes in files with "same name" but with a different Case this might also cause the same problem Nov 16, 2018 at 20:50
  • I had a name change of the parent folder after the initialization of the repo causing the error. The issue did not disappear even when I just changed the name back - of course all with a reload of my editor. I created a new repo inside a rightly named parent folder to solve this. Jul 14, 2020 at 15:58
34

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
1
  • Thanks a lot! This really helped me. For some reason, my file was excluded (was not in .gitignore so not sure why!), and this fixed my problem!
    – benmaq
    Feb 18, 2020 at 11:50
21

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.

1
  • 2
    I'm sure I could have used git add .. or whatever required to get to the level under which my changes existed and it also would have worked. This is just a gotcha problem here (my user error).
    – gaoagong
    Feb 23, 2017 at 21:55
16

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.

1
  • 3
    ...thinking of this, git could add a message if any of the given paths is entirely already in the repository... it would have saved at least 13 people a few minutes.
    – jjmontes
    Feb 15, 2020 at 20:46
13

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.

1
  • I'd also add to double check that the files aren't somehow "already added" or not...
    – rogerdpack
    Apr 2, 2013 at 13:46
10

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.

1
  • This worked for me using git on CygWin and getting some "permissions out of order" messages. I didn't even need to clone and copy the changed files, I just duplicated the directory as it was. I think forcing Windows to re-write everything means that it corrects the permissions problems.
    – RoG
    Jan 24, 2017 at 8:35
5

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.

1
  • For me it was the other way around. I was in a merge (rebase) conflict and I had to cd into the folder to git add the file.
    – LosManos
    Apr 26, 2019 at 19:46
3

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.

1
  • 8
    Please note, git is not able to store empty folders. TY!
    – Blundell
    Nov 22, 2012 at 11:35
3

Here you can find an answer to the same problem:

basically in this case the problem was the global_git ignore

3

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

2

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.

2

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

2

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 :)

2

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

2

I had this issue today. Couldn't figure it out. Then I realised I was in a subfolder instead of the project root. So the resolution was to cd .. into the project root and try again.

1

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.

1

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
1

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.

1

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]

0

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]

0

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.

1
  • That's happening for me on Windows too, I used git bash on that OS to create Aux.js file normally
    – Alex
    Aug 30, 2019 at 21:00
0

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.

0

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"

0

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.

0

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

0

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

0

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

0

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.

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.