nZac

Using Git Worktree with Terraform

I've been test driving Git worktrees in a terraform project and it's been rather slick.

This is the folder structure I'm using

projects/
โ””โ”€โ”€ infrastructure/
    โ”œโ”€โ”€ main
    โ”œโ”€โ”€ feature-branch-1
    โ””โ”€โ”€ feature-branch-2

In my projects directory I have an infrastructure folder which is the same name as the repo.

From inside projects/infrastructure I git clone the default branch into a folder with the same name, normally main.

Then I cd main and run my git worktree add ../feature-branch-1 feature-branch-1. Now I have a new worktree for that branch which I normally open in a new tmux window.

One annoyance is needing to copy over any hidden files between worktrees. A simple solution is to have a mise task to do that and pull the files from a specific worktree.

All in all, it's been a big productivity booster.

#git #terraform