Search code examples
reactjsgithubdirectoryfilepathgitignore

Adding a particular file from a folder to .gitignore


src/
.gitignore

My directory looks like this. There is a keys.js file inside src folder. How do i add keys.js to .gitignore ? I have tried various paths but none of it is working


Solution

  • If your file is already being tracked by git, first try to remove it from the cache :

    git rm --cached <file-path>

    In your case it would be git rm --cached src/keys.js

    Git will delete this file just from the cache ,to be precise from git repository. The file still remains in your working area for you to work upon.

    You will need to commit this change.

    And then modify your .gitignore file with below pattern, assuming your src is directly sitting under the root directory as is the case for most react apps, at least the ones created with create-react-app (for future refrence keep this doc handy)

    /src/keys.js