Go’s build conventions are simple: source code in .go files, compiled binaries with no extension (or .exe on Windows), and a handful of standard tool outputs. The .gitignore is correspondingly short. The list above is a known-good set; this page explains each entry.
Compiled binaries
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
go build produces a binary named after the package directory, with no extension on Linux/macOS and .exe on Windows. Plain * is too broad (it would match the gitignore itself, README, etc.); the explicit-extension form catches Windows binaries and shared library outputs.
For Linux/macOS binaries with no extension, the typical pattern is to name them in .gitignore:
# Project-specific binary names
/myapp
/cli-tool
/backend-server
Or to commit binaries to a bin/ subdirectory and ignore that:
bin/
Either approach is reasonable.
Test binaries
*.test
go test -c compiles a test binary named <pkg>.test. Regenerable; not useful to commit.
Coverage and profiling
*.out
*.prof
coverage.txt
coverage.html
go test -coverprofile=coverage.out and go tool pprof generate .out and .prof files in standard locations. Regenerable.
Vendor directory
# vendor/
Note the comment marker. Whether to commit vendor/ depends on the project:
- If you use module mode (the default since Go 1.13) without
go mod vendor: there is novendor/directory; nothing to ignore. - If you use
go mod vendorto vendor dependencies: the convention is to commit thevendor/directory. It locks the exact dependency source for reproducible offline builds. Don’t ignore it. - If you have a legacy GOPATH project that has
vendor/for unrelated reasons: depends on the project’s policy.
The default in this list comments out the vendor/ ignore (so it’s not ignored) because the modern convention is “if you vendor, commit; if you don’t vendor, there’s nothing to ignore.”
Module files
# Don't ignore these:
# go.mod
# go.sum
Both should be committed. go.mod is your dependency specification; go.sum is the integrity-check lockfile (analogous to package-lock.json or Cargo.lock). Without go.sum, go mod download can’t verify dependency contents.
IDE and editor
.idea/
.vscode/
*.swp
*.swo
Standard. As elsewhere, .vscode/ is contentious — some teams commit a curated subset.
Build artifacts in non-default locations
dist/
build/
release/
If you use a Makefile, GoReleaser, or another build tool that writes outputs somewhere other than the package directory, ignore those directories.
Air / live-reload
tmp/ # air's default reload directory
.air.toml # air config — sometimes committed, sometimes not
Air is a popular live-reload tool for Go development. It writes rebuilt binaries to tmp/. The config file is project-relevant; the tmp/ directory is not.
Common pitfalls
- Ignoring
*.go. Don’t. That’s your source code. - Ignoring
vendor/reflexively. If you use vendoring, thevendor/directory should be committed. - Ignoring
go.sum. Don’t. It’s the integrity lockfile — without it,go modcan’t verify dependency hashes. - Forgetting Windows binaries. A
*.exeignore catches them; without it,go buildon Windows produces a binary that gets accidentally committed. - Project-specific binary names. A pattern like
/cmd-nameonly matches at the root. If your binary is built deeper in the tree, the pattern needs to match that path. - Committing benchmark output and pprof traces. They have legitimate research value but are large and per-run. Use
*.outand*.profignores or commit them to a separatebenchmarks/repo.
For other stacks, see Python, Node.js, Java, Rust, .NET, Ruby, or the general .gitignore generator.