This is a quick article to share a couple of ways in which you can quickly find and create .gitignore
files for which ever technology or language you are working with.
What Is a Git Ignore File, and What Does It Do ?
A Git ignore file is a text tile that sits inside your project directory, and tells Git which files or directories it should ignore in the project folder. Typically a local .gitignore
file sits in the root directory of the project. Note, that you can also have a global .gitignore file, which applies to all of your Git enabled folders.
What Does a Git Ignore File Look Like ?
Below is an example of a .gitignore
file you might use for a Terraform project:
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
# Exclude all .tfvars files
*.tfvars
# Ignore override files
override.tf
override.tf.json
*_override.tf
*_override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
As you can see, it is a fairly simple file, with the filenames, directories or file extensions of the files we wish Git to ignore, and therefore not check into a Git repo during a commit. Each line in the file lists a file or folder that you wish Git to ignore. Also you can use *
as a wildcard match.
How to Create a Git Ignore File
As you can see, creating a .gitignore file is simply a case of creating a text file in your project directory and naming it .gitignore
. However, rather than writing the content of the file yourself, or at least all of it, there are a some resources available to give you a head start.
The first one I wanted to mention are the .gitignore templates available at GitHub. Here you will find git ignore template files covering lots of technologies/languages.
The second resource I wanted to mention can be found at gitignore.io, which is a site which allows you to select a technology (or more than one), and a example .gitignore
file will be generated.
Clicking create results in the following file being created:
# Created by https://www.toptal.com/developers/gitignore/api/terraform
# Edit at https://www.toptal.com/developers/gitignore?templates=terraform
### Terraform ###
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.tfvars
# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
# Ignore CLI configuration files
.terraformrc
terraform.rc
# End of https://www.toptal.com/developers/gitignore/api/terraform
Hopefully you will find this useful when creating your own .gitignore
files!