Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add empty folder

Tags:

git

I added an empty folder named "test" in master folder and I want to update my github.

I typed

git add .
git commit -m "all file"

and it show

#On Branch master
nothing to commit, working directory clean

Why?

like image 219
Dreams Avatar asked Feb 04 '26 18:02

Dreams


1 Answers

Git does not track directories. It tracks files. Directly from Git FAQ (emphasis added)

Can I add empty directories?

Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it. Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own. You can say "git add " and it will add the files in there. If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose (there is also a tool MarkEmptyDirs using the .NET framework which allows you to automate this task); you can leave it empty or fill in the names of files you do not expect to show up in the directory.

So as the FAQ suggests, if you really need to add an empty directory to your repo you can create any file in it. I usually put an empty .gitkeep file inside the empty folder I want to track and that allows me to add it to the repo.

like image 134
Gabriele Petronella Avatar answered Feb 06 '26 08:02

Gabriele Petronella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!