In this Terraform blog post, we will show how to create a global git ignore file and ignore specific files or patterns from being tracked by Git.
Git Ignore is a feature in the Git version control system that allows us to exclude specific files and directories from being tracked by Git and sync to a repository.
The primary purpose of Git Ignore is to prevent sensitive files from being committed to a repository.
Create a .gitignore File
To create a .gitignore file, use the following command and create the file outside your repository.
Open the file and copy the content below
# Ignore Terraform state files
# Ignore .terraform directory
# Ignore any local backup files
# Ignore logs
# Ignore Mac files
# Ignore VS Code settings
# Ignore Terraform plan output files
# Ignore sensitive files with secrets or API keys
# Ignore any generated files or directories
Open a terminal window and run the following command from any repository directory you would like to apply the Git Ignore file to.
git config --global core.excludesFile ~/github/.gitignore_global