DEV Community

Clendon DuRapau
Clendon DuRapau

Posted on

Stop Tracking Files in .gitignore

Git workflow can get out of sync between team members, causing some very frustrating merge conflicts. In the excitement of getting a new project rolling and setting up the repository, it’s easy to start making commits without realizing that you’ve forgotten to add that pesky package-lock.json to .gitignore or even the target path where all your transpiled files end up.

This can cause things to get ugly fast when working with a team.

Here’s the fastest and easiest solution I have found.

  1. edit your .gitignore file and add the files you do not want tracked.
  2. run the following in the root directory of your project

    git ls-files -c --ignored --exclude-standard -z | xargs -0 git rm --cached
    
  3. Make a new commit

    git commit -m "Stopped tracking and deleted files in .gitignore"
    

Caution:

  • The ignored files will not automatically be deleted from your local repository after taking these steps. You will have to do that manually if you want to get rid of them.
  • If you push your changes to a remote repository, when other team members pull the changes to their local repositories, git will delete the ignored files from their machines. This means that those team members will have to rebuild those transpiled files with the compiler used in the project or the package-lock.json with either

    npm install
    

    or

    npm ci
    

Top comments (0)