Reputation: 2195
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?
Upvotes: 124
Views: 261309
Reputation: 407
Had a similar problem, on my side, it was a nested project which had its own git local repository (not intentional). What solved it was to manually delete the embeded .git directory
Upvotes: 0
Reputation: 2285
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:
.gitignore
and .git/info/exclude
.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
git rm --cached path_to_submodule
.Upvotes: 188
Reputation: 1345
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.
Upvotes: 2
Reputation: 347
I've had this come up before, especially when I'm tidying up (fail merges tend to throw up this sort of thing)
I find resetting and adding it onto the last commit tends to pick it up
git reset HEAD^
Upvotes: -2
Reputation: 1
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.
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 305
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.
Upvotes: 0
Reputation: 145
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]
Upvotes: 1
Reputation: 11
In such cases, please check for rules in global .gitignore file and make sure that your folder does not fit into those.
Upvotes: 0
Reputation: 56341
Similar happened for me when I renamed a file between Uppercase/Lowercase
. So, temporary file renaming might fix problem.
Upvotes: 0
Reputation: 9512
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:
The Parent folder that I had opened mistakenly on parent level (vscode_git in my case):
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)
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
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'
:
Then, by simply opening the actual repo folder instead,
the git worked as expected again. Of course the ".git" folder of the parent folder could be deleted then:
Upvotes: 3
Reputation: 1
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
Upvotes: 0
Reputation: 361
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
).
Upvotes: 3
Reputation: 108
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.
Upvotes: 1
Reputation: 1
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.
Upvotes: 0
Reputation: 2805
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"
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 164
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
Upvotes: 1
Reputation: 3571
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.
Upvotes: 0
Reputation: 741
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 :)
Upvotes: 2
Reputation: 1255
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.
Upvotes: 22
Reputation: 7866
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.
Upvotes: 1
Reputation: 61
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.
Upvotes: 5
Reputation: 58
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]
Upvotes: 0
Reputation: 1770
Here you can find an answer to the same problem:
basically in this case the problem was the global_git ignore
Upvotes: 3
Reputation: 3345
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:
setup-temp
git add -A
git commit -m "Whatever"
git add -A
git commit -m "Whatever"
Upvotes: 45
Reputation: 341
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
Upvotes: 34
Reputation: 1957
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.
Upvotes: 13
Reputation: 1078
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.
Upvotes: 2