How To Create a Global Git Ignore File for Terraform

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

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.

touch .gitignore_global

Open the file and copy the content below

# Ignore Terraform state files
*.tfstate
*.tfstate.*

# Ignore .terraform directory
.terraform/

# Ignore any local backup files
*~

# Ignore logs
*.log

# Ignore Mac files
.DS_Store

# Ignore VS Code settings
.vscode/

# Ignore Terraform plan output files
*.tfplan

# Ignore sensitive files with secrets or API keys
secrets.tfvars
*.pem

# Ignore any generated files or directories
/bin/
/out/

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



Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.