-3

I have a project with directory uploads/ which has subdirectories /images and /files. I want to ignore commiting files from these two subdirectories uploads/images and uploads/files but i want .gitignore file to be in root directory.

3
  • Just add those two to your .gitignore then. What is the problem, exactly? Commented Mar 10, 2015 at 8:45
  • 1
    This is one of the most frequently asked questions in the git tag. Please make sure to search before submitting a new question. Commented Mar 10, 2015 at 9:24
  • possible duplicate of How to ignore all files in a folder with a git repository in SourceTree? Commented Mar 10, 2015 at 9:25

1 Answer 1

1

Simply add in the .gitignore:

/uploads/images/ /uploads/files/ 

That will ignore the content of those folders, provided they were not already versioned.
If they were, you would need to remove them from the index and commit (recording the deletion from the repo, not from the disk: --cached)

git rm -r --cached uploads/images git rm -r --cached uploads/files 

but this ignore even the folders, not only content, I want to ignore only content of those folders

One trick is to ignore the all folder (as described above), and then do:

touch uploads/images/.keep git add --force uploads/images/.keep touch uploads/files/.keep git add --force uploads/files/.keep git commit -m "keep fodlers" 

That means you need to have some content in order to keep the folder in the repo (an empty folder would not be tracked by Git).

Sign up to request clarification or add additional context in comments.

3 Comments

but this ignore even the folders, not only content, I want to ignore only content of those folders
@PYovchevski Git doesn't track directories. At all. Ever.
@PYovchevskiI have edited the answer in order to keep the folder while ignoring their content

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.