0Pricing
DevOps Bootcamp · Lesson

Version Control with Git

Integrate your Terraform configurations with Git for version control, branching, merging, and collaborative development.

Version Control with Git is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Git for Infrastructure

Managing infrastructure as code (IaC) means treating your infrastructure configurations like software code. Just like software, these configurations benefit greatly from version control.

Git is the most popular tool for version control. It helps you track changes, collaborate with teammates, and revert to previous versions if something goes wrong with your Terraform.

Initialize Git in Terraform

To start tracking your Terraform project, you first need to initialize a Git repository in your project's root directory. This creates a hidden .git folder.

Let's imagine you have a main.tf file ready.

git init

Stage and Commit Your Code

After creating or modifying your Terraform files, you need to "stage" them (git add) and then "commit" them (git commit) to record the changes in your repository's history.

Each commit should represent a logical set of changes with a clear message.

git add main.tf
git commit -m "Initial commit of main.tf"

Keep State Files Private

Terraform creates state files (like terraform.tfstate) and temporary directories (.terraform/) that should not be committed to Git. These contain sensitive info and can cause conflicts.

Use a .gitignore file to tell Git which files to ignore.

# Terraform specific files
.terraform/
*.tfstate
*.tfstate.*

Branch for New Features

Branching allows you to work on new features or bug fixes in isolation from the main codebase. This prevents breaking the main development line.

  • The default branch is often main or master.
  • Create new branches for specific tasks.
git branch
git checkout -b add-s3-bucket

Develop in Isolation

Once on your new branch (e.g., add-s3-bucket), you can make changes to your Terraform configuration without affecting the main branch.

Let's add a simple S3 bucket resource to our main.tf.

resource "aws_s3_bucket" "example" {
  bucket = "my-unique-bucket-name-123"
}

Merge Back to Main

When your feature is complete and tested on its branch, you can merge it back into the main branch. This integrates your changes into the primary codebase.

First, switch back to main, then merge your feature branch.

git checkout main
git merge add-s3-bucket

Handling Merge Conflicts

Sometimes, when merging, Git can't automatically combine changes. This is a merge conflict. You'll need to manually edit the conflicted files to choose which changes to keep.

After resolving, git add and git commit the merged file.

Share with Remote Repos

To collaborate, you'll push your local changes to a remote repository (like GitHub or GitLab). Others can then pull these changes to their local machines.

This allows teams to work on the same Terraform project simultaneously.

git remote add origin https://github.com/your-org/your-repo.git
git push -u origin main

Git Workflow Check

You've just added a new resource to your main.tf file and want to save these changes to your Git history. Which Git commands would you typically use?

Git for Terraform Recap

In this lesson, we explored how Git is essential for managing your Terraform configurations. You learned to:

  • Initialize a Git repository and track changes.
  • Use .gitignore to exclude sensitive files.
  • Work with branches for isolated development.
  • Merge changes and handle conflicts.
  • Collaborate using remote repositories.

Git ensures your IaC is versioned, auditable, and collaborative!

Frequently asked questions

Is the “Version Control with Git” lesson free?

Yes — the full text of “Version Control with Git” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Version Control with Git”?

Integrate your Terraform configurations with Git for version control, branching, merging, and collaborative development. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Version Control with Git” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Code Structure and Naming Conventions
  2. Version Control with Git
  3. Team Collaboration and Workflows
  4. Documentation and Self-Service Workflows
← Back to DevOps Bootcamp