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


#1

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.