On most projects, there are going to be some files you don’t need or want in its git repo, but you might not always think about them until they’re already in there. When the project involves Sass, the Sass cache directory is one of those things that aren’t really needed or wanted in the repo. No sweat, this is a fixable issue.
First things first, back up the directory:
cp .sass-cache .sass-cache2
Next, enter the following command:
git filter-branch -f --tree-filter 'rm -rf path/to/your/.sass-cache' HEAD
Now if you try to push to your remote like normal, you will probably get an error with something like this:
! [rejected] master -> master (non-fast-forward)
This is because, as the error will explain, your remote repo now has files that your local repo is missing. You want to remove the .sass-cache from the remote, too, so force the push like this:
git push origin master --force
Make sure to change the branch name from “master” to the branch where you want to code pushed, of course. The important part here is just the “–force” flag.
When the push is sucessful, go ahead and take a look at the files in the remote branch where you pushed the code. The .sass-cache directory won’t be there. Nice! You’re a little closer to having a cleaner Git repo.
But you don’t want to do this again, right? If you don’t already have a .gitignore file, put one in the root directory of your local repo:
Replace “nano” with your preferred terminal text editor. Now add the following and save the file:
Go ahead and check the status of your local repo:
You won’t see Git telling you there’s .sass-cache files to add to staging. It ignored them, as we desired.