Lukas Lukac
Lukas Lukac

Reputation: 8346

git didn't push empty folders

I init folder. Added all files commit them and than push them. Everything was looking fine...but i am missing some files and folder.

To example my .gitignore file

web/images/uploaded_profile_pictures/*

But there should be uploaded_profile_pictures folder... how to write it in .gitignore to ignore ONLY the content of the folder.. and keep the folder?

And second problem... why is there missing content???

After push

enter image description here

Upvotes: 4

Views: 6786

Answers (2)

jwhb
jwhb

Reputation: 546

There can't be folders without files in Git repositories, Git will always ignore empty folders (or folders that contain only ignored files). A common workaround is to create placeholder files in empty directories that you want to include in your Git repository.

touch web/images/uploaded_profile_pictures/.empty
git add web/images/uploaded_profile_pictures/.empty

Now for the .gitignore:

web/images/uploaded_profile_pictures/*
!web/images/uploaded_profile_pictures/.empty
# or just
!.empty

This will make Git ignore all files in that folder except of .empty, allowing you to add the folder to the repo.

For the second question: What kind of files are missing? Are those just random ones?

Upvotes: 10

Colin Hebert
Colin Hebert

Reputation: 93157

As @Uroc327 mentioned in his comment, git doesn't handle "folders and files" but instead it uses "content".

This means that an empty folder is simply non existent to git.

This is a common problem, and the simplest solution is to add some "fake content" (an empty file) to a folder.

As @jwhy said, you could create a file named empty.
A more elegant approach (in my opinion) would be having in the folder web/images/uploaded_profile_pictures a file named .gitignore which contains the following:

*
!.gitignore

Upvotes: 2

Related Questions