<p>Using git for <a href="https://www.terraform.io/docs/state/remote.html" rel="nofollow noreferrer">terraform remote state management</a> is an interesting, but non-standard implementation. Storing binary / large files in git, integrating a locking system and a few other concerns come to mind. Using s3, Buckets or other storage options provide the multiple statefile management (versions in buckets, folders in buckets or <a href="https://www.terraform-best-practices.com/code-structure" rel="nofollow noreferrer">terraform folder structure</a> / <a href="https://www.terraform.io/docs/state/workspaces.html" rel="nofollow noreferrer">workspaces</a>) and other functionality you mentioned.</p>
<p>If you would like to pursue using git for remote state management, check out the community project <a href="https://github.com/plumber-cd/terraform-backend-git" rel="nofollow noreferrer">terraform-backend-git</a>. There is also a good discussion around it in the terraform issues section: <a href="https://github.com/hashicorp/terraform/issues/16616" rel="nofollow noreferrer">https://github.com/hashicorp/terraform/issues/16616</a>.</p>
<p>If you attempt to use the tool from the community, it would be great to hear about your experience. Good luck!</p>

CC BY-SA 4.0
2020-08-30T15:25:24.897Z
Thanks, the github project is useful. As for the github issue on the HashiCorp Terraform project, they've closed it, not sure why it wasn't pursued.
Haneef Ibn Ahmad
CC BY-SA 4.0
2020-08-30T15:08:02.850Z
2020-08-30T15:08:02.850Z
George
<p>I see that there are multiple options for Backends, however git isn’t one of them.</p>
<p>I believe git can be used as a backend for tfstate, in the below steps:</p>
<ol>
<li>Create a dedicated git repo</li>
<li>Commit the tfstate files in a specified directory and branch. Only fetch the required files, rather than the whole repo, as this repo could be used to store multiple tfstate files on different directories.</li>
<li>For locking and unlocking:
Method 1 (git LFS): use ‘<a href="https://github.com/git-lfs/git-lfs/wiki/File-Locking" rel="nofollow noreferrer">git lfs lock</a>’</li>
</ol>
<p>Method 2 (git - where lfs isn’t possible): Use another file suffixed with .lock, which should contain the lock state.</p>
<p>Is there any plan for Terraform to release git as a backend?</p>
<p>I've also thought of ways to use the HTTP backend to upload to a git, no luck yet.</p>
<p>Thoughts on how this can be achieved?</p>
<p>There's already a Github/Gitlab/Bitbucket provider.</p>
<p>Thanks,</p>
<p>Note: <a href="https://discuss.hashicorp.com/t/dedicated-seperate-git-repo-as-terraform-remote-backend/12748" rel="nofollow noreferrer">Also asked in the Terraform Discuss</a></p>

<terraform><git>
Dedicated/Separate Git Repo as Terraform Remote Backend
Haneef Ibn Ahmad
# Dedicated/Separate Git Repo as Terraform Remote Backend

(Asked by: username_0 on 2020-08-14)

I see that there are multiple options for Backends, however git isn’t one of them.

I believe git can be used as a backend for tfstate, in the below steps:

1. Create a dedicated git repo
2. Commit the tfstate files in a specified directory and branch. Only fetch the required files, rather than the whole repo, as this repo could be used to store multiple tfstate files on different directories.
3. For locking and unlocking:
   Method 1 (git LFS): use ‘[git lfs lock](https://github.com/git-lfs/git-lfs/wiki/File-Locking)’

Method 2 (git - where lfs isn’t possible): Use another file suffixed with .lock, which should contain the lock state.

Is there any plan for Terraform to release git as a backend?

I've also thought of ways to use the HTTP backend to upload to a git, no luck yet.

Thoughts on how this can be achieved?

There's already a Github/Gitlab/Bitbucket provider.

Thanks,

Note: [Also asked in the Terraform Discuss](https://discuss.hashicorp.com/t/dedicated-seperate-git-repo-as-terraform-remote-backend/12748)

**Tags:** terraform, git


---

## 1 answers

### Answer by username_1 on 2020-08-30. Score: 1

Using git for [terraform remote state management](https://www.terraform.io/docs/state/remote.html) is an interesting, but non-standard implementation. Storing binary / large files in git, integrating a locking system and a few other concerns come to mind. Using s3, Buckets or other storage options provide the multiple statefile management (versions in buckets, folders in buckets or [terraform folder structure](https://www.terraform-best-practices.com/code-structure) / [workspaces](https://www.terraform.io/docs/state/workspaces.html)) and other functionality you mentioned.

If you would like to pursue using git for remote state management, check out the community project [terraform-backend-git](https://github.com/plumber-cd/terraform-backend-git). There is also a good discussion around it in the terraform issues section: <https://github.com/hashicorp/terraform/issues/16616>.

If you attempt to use the tool from the community, it would be great to hear about your experience. Good luck!

> **Comments:**
> **username_0**: Thanks, the github project is useful. As for the github issue on the HashiCorp Terraform project, they've closed it, not sure why it wasn't pursued.  

---

