EN VI

how to ignore a specific subfolder in GitHub without removing the parent folder using .gitignore?

2024-03-13 16:30:04
how to ignore a specific subfolder in GitHub without removing the parent folder using .gitignore?

I'm working on a project in Git and I want to ignore a specific folder ./unit_testing/test_cache. However, i need to keep ./unit_testing folder itself. But When I push my code in GitHub this ./unit_testing folder are removed in GitHub repository.

Directory Structure:

.

├── unit_testing 

│   └── test_cache

│       └── test_output.txt

└── test_project.py

.gitignore file:

/unit_testing/test_cache

I added a exclude pattern to my .gitignore file !/unit_testing However, the ./unit_testing folder is still being removed from my repository when I push my code to GitHub.

Updated .gitignore File:

!/unit_testing
/unit_testing/test_cache

Solution:

As far as I know you can't push an empty directory to git (and even if you are able to, you are not able to pull it down). Edit: see this discussion: How do I add an empty directory to a Git repository?

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login