Subdirectory ignored in .gitignore whitelist

This question already has an answer here:

  • Git Won't Un-Ignore a Directory

    4 answers

  • How to ignore several directories in Git
  • Specify folders to merge with git
  • How can I undo a git rebase that's already been pulled/merged?
  • Sharing Git Patches between IntelliJ Idea & Eclipse
  • How do you handle Doctrine Migrations when using Git?
  • commit one at a time in git
  • Get a graph/data that shows (last 1 year) on code checkins
  • Convert Git submodule to subtree
  • Can Git diff parameters improve source code change alignment?
  • circleci deployment to heroku failed on git push
  • How do I preserve tags when filtering a repository?
  • How can I undo the change to repository after I did 'git checkout SHA'
  • One Solution collect form web for “Subdirectory ignored in .gitignore whitelist”

    From the docs:

    It is not possible to re-include a file if a parent directory of that file is excluded

    You need to explicitly unignore both the directory and its contents, or else the ignore rule negating the contents cannot match anything. First, unignore scripts, and then you can unignore scripts/*.

    Here is the working .gitignore:

    *
    !.gitignore
    !scripts
    !scripts/*
    

    That said, because you’re unignore *, you can get away with just one rule, which unignores the path scripts. The second scripts/* is redundant.

    Git Baby is a git and github fan, let's start git clone.