1

I get the said error when I run the code git status /path/to/file or like git add "/path/to/file/README"

I've initialized the /path/to/file using init git init /path/to/file. This seems to work fine

From git manual git status [<options>...] [--] [<pathspec>...] I understand this means I can add /path/to/file (also answered here) or did I get it wrong?

Tried the answers from here and also the links (under This question already has an answer here:) in it.

git clone url /path/to/file works fine but git status /path/to/clone/ gives the same error

Tried Uninstalling and re-installing git. git version is 2.14.1 running on Ubuntu 17.10

Edit: If I cd /path/to/file and run git status, it works fine.

1565986223
  • 6,420
  • 2
  • 20
  • 33

2 Answers2

2

Git needs to know where the repository is, running git status /path/to/dir is not enough. Either the current directory is a (sub)directory of a repository (that is, cd /path/to/dir) or you explicitly say where the repository is:

git --git-dir=/path/to/dir/.git --work-tree=/path/to/dir status README

or

GIT_DIR=/path/to/dir/.git WORK_TREE=/path/to/dir git status README

Seems like cd is the shortest and simplest solution.

phd
  • 82,685
  • 13
  • 120
  • 165
  • 2
    Is it `--work-tree`? (that's what `man git` gives me; `Unknown option: --work-dir=` error displayed). Also `git -C /path/to/dir/ ` works. Thanks for the help. – 1565986223 Mar 25 '18 at 13:21
  • 1
    `git -C "path_to_dir" ` worked perfectly! As a side note, putting the path in double quotes allows paths with spaces to be resolved correctly. – Jeromy Adofo Sep 29 '20 at 10:03
0

Yes I had the same issue, I wasn't in the same directory as the project (since after cloning it, you have to cd into it).

Taniya
  • 1
  • 1