62

I want to add all files no matter what: whether it is deleted, created, modified, untracked, etc? I just don't want to git add ALL my files EVERY TIME. I tried git add -A but it is NOT adding modified files inside folders.

Here is my initial git status in my project:

Rakib-MacBook-Pro:my-xcode-practice rakib$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   BankAccount (modified content, untracked content)
#   modified:   BuckysButtons (modified content, untracked content)
#   modified:   multiview (modified content, untracked content)
#   modified:   rotator (modified content, untracked content)
#   modified:   segmentedControls (modified content, untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

Then I put git add -A:

Rakib-MacBook-Pro:my-xcode-practice rakib$ git add -A

and then here is the new status AFTER doing git add -A:

Rakib-MacBook-Pro:my-xcode-practice rakib$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   BankAccount (modified content, untracked content)
#   modified:   BuckysButtons (modified content, untracked content)
#   modified:   multiview (modified content, untracked content)
#   modified:   rotator (modified content, untracked content)
#   modified:   segmentedControls (modified content, untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

You can see that there has been no change in the git status. How do I solve this?

I also tried git add . - it did not help

I also tried git add * - it did not help

Kevin Bowen
  • 1,625
  • 2
  • 23
  • 27
Rakib
  • 12,376
  • 16
  • 77
  • 113
  • that's weird. How do you actually add the files now? – Pablo Fernandez Oct 11 '11 at 12:47
  • Can you check `git add .; git add -u`? Explanation: http://stackoverflow.com/questions/572549/difference-of-git-add-a-and-git-add – Marcin Gil Oct 11 '11 at 12:47
  • Did you try to run `git commit -a -m "just commit"` ? Did you add BankAccount etc to your `.gitignore` ? – DipSwitch Oct 11 '11 at 12:48
  • @DipSwitch i have tried 'git commit -a -m' and just commit - no luck – Rakib Oct 11 '11 at 13:34
  • @DipSwitch i have not added anything in the ignore list – Rakib Oct 11 '11 at 13:34
  • @MarcinGil i have tried `git add .` - i have tried `git add -u` - i got same result – Rakib Oct 11 '11 at 13:35
  • @PabloFernandez i am not able to add any files now...... just the folders are getting added.... not the contents inside the folders. Hence my pushes are containing only the folders with nothing inside them – Rakib Oct 11 '11 at 13:36
  • What does `git ls-tree HEAD BankAccount` output? If it starts with `160000 `, then your repository sees the `BankAccount` directory as a submodule. If it's listed as `160000 `, and you don't have a `.gitmodules` file, then that would explain why `git status` shows what it does. – Go Dan Oct 11 '11 at 14:20
  • @Dan Cruz: I think we've already established below that that's the case - the output `(modified content, untracked content)` in `git status` is only shown for submodules or nested repositories, and the errors that syedrakib quotes in the comments on my answer tells us it's the latter. (i.e. at least `.gitmodules` is missing, and probably the `submodule.[SUBMODULE-PATH].url` config options as well.) – Mark Longair Oct 11 '11 at 14:32
  • @DanCruz - you are right. it has output 160000 - now who would have known that??? thanks – Rakib Oct 11 '11 at 14:52
  • @MarkLongair has said it correctly that in the answer below that this is happening because of submodules. – Rakib Oct 11 '11 at 14:52
  • how have i solved it? I removed the .git directories inside the sub-directories called BankAccount , BuckysButtons , rotator etc. – Rakib Oct 11 '11 at 14:52

9 Answers9

48

The problem here is that BankAccount, BuckysButtons, multiview, rotator and segmentedControls are all git submodules, which act like independent repositories in many ways.

If what you want to do is to run git add -A . in each submodule, you could do:

git submodule foreach --recursive git add -A .

And then you could create a commit in every submodule with:

git submodule foreach --recursive "git commit -m 'Committing in a submodule'"

(If you don't have other submodules nested inside those submodules, the --recursive option is unnecessary.)

However, I don't recommend doing this. You should carefully change into each submodule in turn, and consider how you want to update them, treating each as a standalone repository. Then only commit these new submodule versions in the main project when you have tested that the project as a whole works with those new versions of each submodule.


Update: It seems from the error message that you've quoted in the comments below that you have added these other git repositories directly rather than as submodules. This can happen if you copy another git repository into your repository and then just use git add to stage it, rather than adding it with git submodule add <REPOSITORY-URL>. If you really intend these to be stored as submodules, I would suggest moving them out of your repository, committing their deletion, and then add them properly as submodules with git submodule add

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • could not use submodule. it says, `git submodule foreach --recursive git add -A .` # Entering 'BankAccount' # No submodule mapping found in .gitmodules for path 'BankAccount' # Entering 'BuckysButtons' # No submodule mapping found in .gitmodules for path 'BuckysButtons' # Entering 'multiview' # No submodule mapping found in .gitmodules for path 'multiview' # Entering 'rotator' # No submodule mapping found in .gitmodules for path 'rotator' # Entering 'segmentedControls' # No submodule mapping found in .gitmodules for path 'segmentedControls' – Rakib Oct 11 '11 at 13:26
  • It would seem at some point those directories were set up as submodules but you are missing the .gitmodules file in your main project directory. – Go Dan Oct 11 '11 at 13:36
  • 1
    In that case, these repositories haven't been added as submodules, you've just added them directly. I've updated my answer to reflect that. – Mark Longair Oct 11 '11 at 13:37
  • however, is the submodule the appropriate way to do such recursive addition of tracking or indexing? shouldn't it be much simpler than all that? – Rakib Oct 11 '11 at 13:42
  • 1
    It is the standard way to do that, yes - most people probably aren't aware that you can add other repositories as entries in your tree *without* using the `git submodule` commands. However, that's not to say that this is necessarily the right approach for you - you might want to look at [git slave](http://gitslave.sourceforge.net/), [git subtree](https://github.com/apenwarr/git-subtree) or [repo](http://source.android.com/source/version-control.html) as possible alternatives. Or it might be better to avoid nesting repositories entirely. – Mark Longair Oct 11 '11 at 14:15
  • Hey @MarkLongair thank you so much for your **update**. it totally addressed my issue. My issue rose up because I copy pasted other project folders (which had .git folders inside them) into my repo. That's where the problem started. – Rakib Oct 11 '11 at 15:01
  • Agree with your answer, but your update confuses me. `you have added these other git repositories directly rather than as submodules` leads me to believe there is some way to produce the OP's output (`# No submodule mapping found in .gitmodules for path `...) by copying another repo as a subdirectory in an existing repo. Am I missing something or is there another way to get this output other than removing the .gitmodules file? Copying another repo as a subdirectory, making modifications in there, and running `git status` does not produce the same output. – Go Dan Oct 11 '11 at 15:06
  • @Dan Cruz: perhaps we have different versions of git? With 1.7.4.1 I can reproduce exactly the same output by copying another repository into my current one, adding it with `git add other-repository`, committing that change, then changing into `other-repository`, creating a new file, modifying an exisiting file, and then changing back into the main repository and running `git status`. – Mark Longair Oct 11 '11 at 15:10
  • 1
    @MarkLongair: You're right; different versions produce different outputs. Did what you said, used `git status` with versions 1.7.0.4 and 1.7.4.1 (built from source) and got different outputs. The 1.7.4.1 version gives output referencing submodules while 1.7.0.4 does not. Learned something new. – Go Dan Oct 11 '11 at 15:29
31

I just recreated this by accident.

I copied a project I had in another folder into my new git repo. I didn't intend to use it as a submodule, I intended to use it as a starting point for a new project. The project I copied which was now a subfolder of my main git repo had .git/ in it. Delete subfolder/.git/.

rm -rf subfolder/.git

Then things were still weird...

git status

Nothing to commit. Hmm... What about all of these files?

The reason is the files are still cached in git as a submodule - this cache needs to be cleared of that:

git rm --cached subfolder

You should now see that all of the files in the subfolder in git status.

You can now commit and push.

git add -A
git commit -m 'fix: rm accidental submodule and readd files'
git push origin <branch>
Patrick Lee Scott
  • 8,217
  • 3
  • 36
  • 42
5

A pretty simple fix for me - I had opened the Git Bash in a subdirectory of the project.

Open the Bash and doing the commands in the root directory fixed this problem; git add -A . worked as expected.

Ben
  • 54,723
  • 49
  • 178
  • 224
4

I solved this by deleting the .git folders inside the supposed submodules and inside the project root, and then doing a new 'git init'

Albert Scholtz
  • 337
  • 3
  • 15
2

This error occurs because you have added a folder which is already linked with some another github repository .

To solve this issue first copy the files you want to upload to github from the BankAccount folder and then delete the BankAccount folder.

Now make a new folder and then paste the files in it.

It is due to the git submodules that is automatically taken by git present in the earlier folder.

Now you can do

git add . 
git status
nilansh bansal
  • 1,404
  • 1
  • 12
  • 23
1

I had a similar problem on Windows where I git add --all left some files untracked, problem was that there were several files with different casing 'test.php' and 'Test.php' so git tracked Test.php and not lowercase version of it.

This may help someone in future and save some head scratching.

insanebits
  • 818
  • 1
  • 6
  • 24
0

I had this very issue the past couple of days with BitBucket. I am working on a project that is being tracked in its repository by Visual Studio 2013 Community Edition.

However I had used Git Bash on occasion to manually do commits and that's when things started to go wrong and files were simply being ignored. Tried to reclone the repo but this didn't help.

Finally I found that if you go into Visual Studio > Team Explorer > click on Sync, Visual Studio will do a pull and then commit and push any untracked files.

You could do the same manually through Git Bash if you like the console like I do.

Hope this helps someone.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Trevor
  • 1,561
  • 1
  • 20
  • 28
0

I had this issue because I cloned somebody else's repository into my project. When I cloned it, there were already .git and .gitignore folders/files from their project. After deleting those pre-existing git files and starting over with git again, it works fine.

AndyZe
  • 49
  • 4
0

Let's quote the documentation for -A:

       -A, --all
       Like -u, but match <filepattern> against files in the working tree in addition to the
       index. That means that it will find new files as well as staging modified content and
       removing files that are no longer in the working tree.

Note the critical word: <filepattern>. You need to give it a pattern that matches, recursively, all the way down your tree.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • i have also tried 'git add *' - that should be the universal pattern right? it did not work either, – Rakib Oct 11 '11 at 13:23
  • * always means 'in the current directory'. Unfortunately, with kernel.org offline in large part, I've failed to find the definition of filepattern for you. – bmargulies Oct 11 '11 at 13:46