Gitignore not working with terraform

I am new to github and I’ve tried a few things to successfully push my code to my github account but it won’t work.

I’m using Visual studio code and want to push some basic Terraform files to my repo. When I go to push the project, it complains about the large file in the .terraform file. But the terraform directory is clearly excluded in the .gitignore file. I’ve done the following:

  1. Created a new public repo and also created a gitignore file based on the terraform template. So the .gitignore file exists in the online repo.
  2. Created a .gitignore file in my local project folder and copied the contents from the online file in the repo.
  3. Performed a push and it still complains about the large .exe file in .terraform.

That looks like that .exe file was already committed to your repository before you added the .gitignore file. A .gitignore file can’t change the repository history, you’ll have to remove the file from history yourself. The procedure is essentially the same as for Removing sensitive data from a repository - GitHub Docs.

For editing repository history (and related pitfalls) in general, see: Git - Rewriting History

yes that’s definitely the issue thanks! But I really wasn’t expecting the fix to be such a headache. Thanks for the links, the first one talks about using git filter-repo, but it requires python to be installed. There must be an easier way to untrack all the initial files?

I’ve also tried following this, but it hasn’t worked, that pesky exe is being tracked by git: Untrack files already added to git repository based on .gitignore - CodeBlocQ

Unfortunately not, unless you want to start over from scratch. Git history is usually meant to be immutable, modifying it is the exception, not the rule.

That guide just adds a commit that removes the files, without cleaning up history. That way the files aren’t being tracked for the future, but are still part of the history. And when you push, all history is pushed. So that guide doesn’t help you here.