DEV Community

Clendon DuRapau
Clendon DuRapau

Posted on

2 1

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
    

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay