Why am I unable to 'git add' a file?

Question

I’m trying to git add <filename.txt> but it’s complaining about not being a git repository, why is this and how do I fix it?

Answer

If you see an error message along the lines of fatal: Not a git repository (or any of the parent directories), this means you’re not in the right directory to be using git commands. Recall that you can only use git commands in a git repo.

To navigate back to where you should be (/home/ccuser/workspace/sorcerers-code) you’ll want to make use of pwd and ls while you cd your way back from wherever you currently are.

Also, be sure to take a look at this handy directory map if you need a reminder of how the structure is set up.

If that still doesn’t fix the issue, be sure you’re correctly typing the filename you want to add. To avoid typos, type the first few letters of the file and press tab and it’ll autocomplete for you.

8 Likes

If you see the fatal: Not a git repository (or any of the parent directories) error, initialise a new Git again in the directory you are working by git init command and try running the git add scene-1.txt

37 Likes

Thanks bro it worked

Thanks was stuck here. Works

Hey, it still doesn’t work for me. I checked the directory and the git init, but it still doesn’t work. I restarted it and refreshed it many times with the same result. can somebody help me?

1 Like

The same! Stuck there. Now it works!:))

it still did not work for me :frowning:

Same hier!
Please help!

I managed to make it work now!
@paulbangle1519982234 did you managed to solve it?
I just did…
I refreshed the page once again and then I did the following:
git init /home/ccuser/workspace/sorcerers-code/.git/ Reinitialized existing Git repository in /home/ccuser/workspace/sorcerers-code/.git/.g it/ ls
add_test.rb init_test.rb scene-1.txt
$ git cd scene-1.txt
git: ‘cd’ is not a git command. See ‘git --help’.

Did you mean this?
add
$ git add scene-1.txt

it worked! :smiley:

4 Likes

Thank you so much! This helped me a lot

What I did: I reseted my progress in this lesson and started it again from 0.

1 Like

Super! Merci beaucoup pour votre aide. Cela fonctionne.

could you please tell me what is wrong?
it should be ok, but not

1 Like

hi!
is anybody there?
I’m stacked on this Git lesson, no logic, no help, no solution to check what I’m doing wrong.
I post question on forum, but no reply either.

Could someone please help me with this issue?
Technical Support told that can not help me with it…
I refreshed the page
I started from the beginning
I tried to use solutions offered here
it does not work

First, reset the workspace, then try the following:

cd /home/ccuser/workspace/sorcerers-code
git init
git add scene-1.txt
git status
5 Likes

Thank you, it worked .

1 Like

thanks for saying directly what to do, it works now

Hi there.

If you’re having trouble, please check that the files are where you expect them to be. From the sorcerers-code directory, if you type ls into bash and hit enter, you should see the scene-1.txt file listed in the output. If it’s not there, you may need to reset the exercise. :slight_smile:

2 Likes

Awesome thank you! I was stuck on that all day!

2 Likes