Skip to content

Go .gitignore

Generate a Go .gitignore — covers compiled binaries, test output, vendor directory, and go.work files. VS Code and macOS files preselected.

A ready-to-use Go .gitignore. Excludes compiled output (*.exe, *.dll, *.so, *.dylib), test artifacts (*.test, *.out), vendor/, and go.work. Add JetBrains if you use GoLand, or Windows/Linux for cross-platform repos.

Languages

Operating systems

Editors

Tools

Pick at least one template

Download
 

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 no vendor/ directory; nothing to ignore.
  • If you use go mod vendor to vendor dependencies: the convention is to commit the vendor/ 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, the vendor/ directory should be committed.
  • Ignoring go.sum. Don’t. It’s the integrity lockfile — without it, go mod can’t verify dependency hashes.
  • Forgetting Windows binaries. A *.exe ignore catches them; without it, go build on Windows produces a binary that gets accidentally committed.
  • Project-specific binary names. A pattern like /cmd-name only 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 *.out and *.prof ignores or commit them to a separate benchmarks/ repo.

For other stacks, see Python, Node.js, Java, Rust, .NET, Ruby, or the general .gitignore generator.