13

I have created a repository in a folder with my project, you know, git init, I have the Webstorm folder .idea and another one not related to this, I am not interested in keeping in the repository, and I don't want this folder to appear even as new files to add. I want to forget about these subfolders.

  1. How can I exclude this subfolder before committing the whole repository?
  2. How can I exclude this subfolder after committing the whole repository?

1 Answer 1

23

Open the .git/info/exclude file in a text editor and add the folder to ignore. This file remains private to you. You can also create a .gitignore file in the repository's root directory, outside the .git directory and write the folder entry there. Then add this file to the repository to share with others what content should be ignored, should others have this directory-to-ignore in their repository too.

If you already committed this directory then just remove it with git rm -r --cached, commit the deletion and mark the directory ignored as I described above. You might want to make a backup of the directory before you wipe it.

5
  • 12
    I would recommend git rm -r --cached instead of git rm -r -- otherwise the directory will also be deleted from your working tree. Commented Nov 8, 2010 at 18:36
  • @Sven Marnach - hehe, that's a good comment, I deleted the folder without wanting, but I didn't need it this time!!! Commented Nov 8, 2010 at 18:43
  • 2
    @Mr Question: If you would still need it, you can of course get it back. That's what a version control system is for after all. Commented Nov 8, 2010 at 18:55
  • I've added the line /css/ to the exclude folder, but I still have a list of deleted files from within that in my working tree. Where am I going wrong?
    – Mild Fuzz
    Commented Mar 2, 2011 at 17:24
  • If you're trying to ignore files in a directory named css then say css/ Commented Mar 3, 2011 at 1:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.