Forgot to add .gitignore how do I sync remote repo

Hi,

I forgot to add a .gitignore file before I pushed some files to the remote repository (i.e. Terraform tfstate file). So now I need to synchronise the remote repository so that my local repo has the tfstate files and the .gitignore file but the remote repository deletes the tfstate file, what’s the best way to do this?

Regards,
Jason

why it was deleted ? by the owner of the repo ?

Hi,

Thanks for your reply. The remote repository shouldnt contain the tfstate file, if I had added the .gitignore file in the beginning that file would have been correctly ignored and not pushed to the remote repository.

So I have now added the .gitignore file but I somehow need to remove the tfstate file from the remote repository while keeping it in the local repo - as it is used when I run Terraform locally.

Jason

What do you mean by “keeping it it the local repo”? If you commit it, it will come along when you push, there’s no way around that.

If you mean that you want to keep the file in the local working tree (but not committed) you can use git rm --cached to remove the file from the index, but leave the file in your working tree alone. Note that you’d then need to make a new commit with the deletion, if you want the file gone from all the repository history you’ll need to rewrite that.