Luce Carter Logo

  • Software Development
  • Git
  • Collaboration

Handling incorrectly committed and pulled folders in a Git repo

I am currently working on a project that involves creating projects in multiple languages that all live within one repo. I am responsible for C# and Ruby. Both of these languages involve creating projects and often using an IDE. They also have dependencies either as NuGet packages or Gems. Both of these generate folders that do not need to be included in the repo. But what happens if you miss one in the .gitignore file and someone pulls down the repo and gets all these files?

This happened to me. I forgot to add .idea and .tmp to the top level .gitignore for the whole multi-language project. Yes you can just add it to .gitignore from then on, but it leaves the folders in place as they are already tracked, and not everyone enjoys being told to go in and delete it manually. But I found out how to fix it!

You want to remove the files and folders from the git cache and commit those changes. This will then delete the files on the local machine of your teammates the next time they ```git pull``.

1. Run git rm -r --cached <name of folder>

2. Run git commit -m "Removed accidental folder"

3. Run git push

Just like that, it should be removed from now on. No more manually deleting of folders you never meant to add!

Luce Carter

Dev 🥑 at MongoDB | Microsoft MVP | Twilio Champion | I help developers build confidence and battle Impostor Syndrome, one line of code or story at a time | She/Her