Git Basics for Go Projects
10 examples to get you started with Git & GitHub - 7 basic and 3 intermediate.
Search across all documentation pages
10 examples to get you started with Git & GitHub - 7 basic and 3 intermediate.
git config --global user.name "You" and git config --global user.email "you@example.com".GOPRIVATE to your org prefix, for example export GOPRIVATE=github.com/myorg/*.Start from the remote that matches your go.mod module path.
git clone git@github.com:myorg/widget.git
cd widget
go test ./...go get resolves the module.go.mod at the repo root defines the module path for imports.Related: Git for Go Teams - why Git and modules share a release story
See tracked changes and whether dependency files drifted.
git status
git diff go.mod go.sumgo.mod / go.sum diffs often mean dependency or tidy changes..gitignore needs /bin/ or *.exe.Related: go.mod, go.sum & Minimal Version Selection - what those files mean
Keep main releasable; branch per change.
git switch -c feat/add-metricsfix/nil-panic, feat/grpc-health).main frequently to avoid go.sum conflicts.Related: Branching Strategies & Trunk-Based Flow - trunk-based habits
Commit compilable units with clear messages.
git add internal/metrics/collector.go internal/metrics/collector_test.go
git commit -m "metrics: add process collector"_test.go files with the code they cover.go test binaries or profile outputs.package: verb matches many Go project conventions.After go get or import edits, tidy and commit module files.
go get golang.org/x/sync@v0.10.0
go mod tidy
git add go.mod go.sum
git commit -m "go.mod: bump golang.org/x/sync"go mod tidy drops unused requires and adds missing indirects.go.sum growth for unexpected transitive modules.Publish work for review without tagging a release yet.
git push -u origin feat/add-metrics-u sets upstream so later git push / git pull work without extra args.main with test plan and module impact noted.go test ./... CI before merging.Related: Code Review with GitHub PRs - PR size and module-aware review
Integrate others' changes and re-run tests.
git switch main
git pull --ff-only
git switch feat/add-metrics
git merge main
go test ./...--ff-only on main avoids accidental merge commits when updating local trunk.go.sum conflicts carefully; re-run go mod tidy after resolution.Use Git history with Go's fast bisect workflow.
git log --oneline -n 10
git bisect start
git bisect bad
git bisect good v1.3.0
go test ./internal/parse -run TestDecodegit bisect pairs well with focused go test package flags.v1.3.0 are valid bisect boundaries for released modules.Related: Rebasing, Cherry-Pick & Worktrees - history hygiene tools
Tag the commit you want module consumers to resolve.
git switch main
git pull --ff-only
go test ./...
git tag -a v1.4.0 -m "v1.4.0: metrics collector"
git push origin v1.4.0-a) for releases; they carry message and tagger metadata.go get github.com/myorg/widget@v1.4.0 after the proxy indexes the tag.Related: Signed Tags & Go Module Releases - signing and proxy behavior
Parallel work without clashing go build outputs.
git stash push -m "wip metrics" -- internal/metrics
git worktree add ../widget-hotfix main
cd ../widget-hotfix
go test ./...go.mod experiments..git database.go test run; module cache is shared.Related: Monorepo Git Patterns with go work - multiple modules, one repo
Stack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify linter set at build).
Reviewed by Chris St. John·Last updated Jul 18, 2026