github/gitignore · Go.gitignore
Go .gitignore Template Explained
Why Go.gitignore ignores binaries, test binaries, coverage profiles and go.work, and why extensionless executables need a separate rule.
Go.gitignore covers built binaries, test and coverage output, and local workspace files. Because Go downloads dependencies into the module cache ($GOPATH/pkg/mod), no huge folder like Node's node_modules appears inside the repository, and the template is short.
go.mod and go.sum are not ignored. These two files record the module's dependencies and checksums, so always commit them.
Rules explained
| Pattern | What it ignores and why |
|---|---|
*.exe*.exe~*.dll*.so*.dylib | Binaries and librariesOutput of go build and shared libraries built with cgo. They are built separately for each platform, so distribute them as release artifacts rather than through the repository. |
*.test | Test binariesTest executables created with go test -c. The package name is followed by .test. |
*.outcoverage.**.coverprofileprofile.cov | Coverage and profilesResults produced by commands such as go test -coverprofile=coverage.out. They are measurements that change on every run. |
go.workgo.work.sum | WorkspacesFiles used when developing several modules together locally; they point to paths on your own disk. The go help work documentation also explains that checking go.work into version control is generally not recommended. |
.env | Environment variablesA file holding local settings and secret values. Commit example files under a different name (for example, .env.example). |
Practical notes
- On Linux and macOS,
go buildproduces an executable without an extension (named after the module). The template cannot block it, so add your own rule such as/myappor/bin/. vendor/is not ignored. Some teams put dependencies in the repository withgo mod vendor, so decide according to your policy.*.outignores every file whose name ends in.out, so if your test expectation files use that extension, add an exception such as!testdata/**/*.out.- If you use GoLand, also select the JetBrains template.
Original template
Go.gitignore
# If you prefer the allow list template instead of the deny list, see community template:# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore## Binaries for programs and plugins*.exe*.exe~*.dll*.so*.dylib# Test binary, built with `go test -c`*.test# Code coverage profiles and other test artifacts*.outcoverage.**.coverprofileprofile.cov# Dependency directories (remove the comment below to include it)# vendor/# Go workspace filego.workgo.work.sum# env file.env# Editor/IDE# .idea/# .vscode/
Templates from github/gitignore/Go.gitignore @356fd7b (2026-09-11) · CC0-1.0