Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I want to check in a blank folder. How can I do this?

2 Answers

0 votes
by (27.5k points)

You cannot commit empty folders in git. In case you want it to show up, you need to put something in it, even just an empty file.

For example, add an empty file called .gitkeep to the folder you want to keep, then in your .gitignore file write:

# exclude everything

somefolder/*

# exception to the rule

!somefolder/.gitkeep 

Commit your .gitignore and .gitkeep files and this should resolve your issue.

0 votes
ago by (1.7k points)

Git doesn’t permit acknowledging an empty folder so a folder must be kept with something in it, even how trivial a file may seem.

First, create an empty folder:

touch somefolder/.gitkeep

For instance, you can place an empty file of .gitkeep type in the directory that you want to keep. Afterwards, in your .gitignore file, use this:

Ignoring the full contents in the folder

somefolder/*

Permit use of only the .gitkeep file

!somefolder/.gitkeep

After committing both .gitignore and .gitkeep files, the folder will be included in your repository.

31k questions

32.7k answers

501 comments

693 users

Browse Categories

...