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

# 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

Leave a Comment

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