1

I have a code repository in Github. I tried adding a new directory in the codebase using the command: git add CodeRevision where CodeRevision is a new directory. I got "fatal: pathspec 'CodeRevision/' did not match any files" message. Is it not possible to add a new directory in GIT?

Arnav Bose
  • 791
  • 4
  • 13
  • 27
  • Git only tracks files, not directories. – SLaks Feb 13 '18 at 18:51
  • 1
    Possible duplicate of [How to commit a directory into a git repository?](https://stackoverflow.com/questions/1573883/how-to-commit-a-directory-into-a-git-repository) – phd Feb 13 '18 at 22:33

3 Answers3

3

Git does not track empty directories. Some people put a .gitkeep inside of the otherwise empty directories they want to track.

Or you could include a .gitignore as explained here.

It really begs the question: If it's empty, why track it? But that's for you to answer.

Drewness
  • 5,004
  • 4
  • 32
  • 50
0

Git only tracks files, not directories.

If you put a file in the directory and add that, the directory will automatically exist.

But there is no way to create an empty directory in git.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

If you're trying to add empty directories into your Git repository. See: How can I add an empty directory to a Git repository?

You need to have content (i.e. a .gitkeep, .gitignore) inside the directory for Git to track.

rogerrw
  • 1,864
  • 3
  • 15
  • 18