Can't Add File to Git

Hey,

I created a new branch and then created a new file git-test.md and tried:

git add git-test.md

But I get this error: fatal: pathspec ‘git-test.md’ did not match any files.

If I git status it shows the file as untracked and tells me to add it.

I can add it using the Source Control panel in VS Code, but not in the terminal.

Anyone know what’s going on here?

Thanks!

did you check your spelling ?
try copying the file name instead of writting it,
you can also add files by entering : " git add ." , this will add all the files that are untracked.

1 Like

Yeah, I’ve tried it a bunch of times, with and without the file path,

I’ve always added all the files at once, but wanted to try just adding one file.

Do you perhaps have your terminal in the wrong directory relative to the file you are trying to add?

1 Like

It’s in the right directory. Thanks for the suggestion though.

Type ls in your terminal to confirm if you have the file in the directory

1 Like

Oh, haha, I’m dumb. I thought I only had to be in the repo folder, and not in the actual folder to add, since I’ve always been able to git add -A, and everything else, from the main folder. I also realized there’s a space in one of the folder names, which is why copying and pasting the file path didn’t work either. Once I put that folder in quotes, that worked as well. @ArielLeslie you were right afterall

Thanks for the help! @joaodiniz @ArielLeslie

I’m glad you were able to figure it out! Git errors can be annoying to debug.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.