11

I'm using Github Desktop and tried pushing a new project into a React_Native repository, however when I try committing the code I'm prompted with "cannot add to the index - missing --add option?", I noticed that this problem occurs after I run "expo init client" to initiate my program. Any help is greatly appreciated. enter image description here

kuassant
  • 121
  • 1
  • 1
  • 3

8 Answers8

15

I had the same problem.

What fixed it for me was I went into the folder using file explorer. Under the view tab, I checked the hidden items box. Then I deleted the .git file.

edit: see @opcode's comment.

  • Deleting the .git folder worked for me as well. Thanks – Pking Jan 20 '22 at 14:11
  • 4
    Just to be clear, for people coming from Google. Don't just delete your git folder but check if you have another .git subfolder first. gitnception causes this error too basically. – opcode Mar 08 '22 at 04:37
  • I some how had a folder with same project name inside my project and was causing this issue. Solution for me was to delete that folder and everything worked like magic. I was working on a Laravel project with a lot of folders so knowing that a folder like this exits was kinda hard to do. – Yasser CHENIK May 09 '22 at 10:32
5

I was very silly and hadn't committed the file yet. Git has to be tracking it first so the files you apply this to can't be new, must be committed first

1

there's a another .git folder nested inside your project. Go and delete that folder to make it work.

0

Look at the first error first, that's likely what's causing the other ones. It's saying that that directory (John_Deere/client/) was not found. That path probably doesn't exist any morel maybe you moved some folders around or something? Try adjusting the expected path and see if that works.

  • thanks for the suggestion, the files and folders are still present in the correct repository folder, has to be something else, my guess is that the problem may relate to react-native – kuassant Dec 05 '21 at 19:17
  • @kuassant -- That's not likely because even the second error is saying that it can't add that directory to the index (probably because there's some problem with that directory). – Voldemort's Wrath Dec 05 '21 at 19:18
0

In my case (same error), i had php container running, with project folder connected as volume to my local storage. Previously I created git repo inside this project folder and this action left some hidden files inside. In my case even 'empty' folder resulted in this error occuring (as i presume due to hidden files still being present). Still not 100% sure what did the trick for me but my guess is on deleting hidden '.git' file (in my case from container cli)

Mefiu
  • 1
  • 1
0

I agree that checking the folder for hidden files - or oddly named files - is a good start to troubleshooting this problem.

Alternatively, you could create a new folder in the destination repository and copy over the specific files you want there - that will likely address the issue for you, too.

Febroo
  • 1
  • 1
0

this happened to me when i cloned another git to a new one . removing the .git from the cloned folder helped me.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 21 '22 at 19:25
0

In my opinion this happens because Github Desktop couldn't add files to staging area automatically, and that's is the reason why you have to do it by yourself.

Using terminal navigate to your project directory (in VS Code you open terminal using CTRL + `. Inside your project directory run git add .After this you can commit using Desktop Github as you usually do or of course you can commit using terminal git commit -m "your commit message".

SadatD
  • 160
  • 7
  • you can commit using git commit via command line as well. It would be good to explain a bit more about why your solution works and what it intend to do. – Farrukh Subhani Apr 04 '22 at 16:18