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?
Asked
Active
Viewed 1,036 times
1
-
Git only tracks files, not directories. – SLaks Feb 13 '18 at 18:51
-
1Possible 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 Answers
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
-
-
-
-
See, I have a folder/directory 'CodeRevision' with 20-odd files inside a directory structure Dashboard/DAM_Application/Alerts/. I want to take it one level up to Dashboard/DAM_Application/. Now at this one level up I do not have any CodeRevision directory. So, I am not able to figure out how i can do this. – Arnav Bose Feb 13 '18 at 19:09
-
-
'make a directory' - which means a new directory, right? then how do i add this new directory inside Dashboard/DAM_Application? – Arnav Bose Feb 13 '18 at 19:13
-
Using the filesystem. Move files where to where you want them to be, then add those files to git. – SLaks Feb 13 '18 at 21:16
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