Question
I want to install a package from GitHub into my $GOPATH using go get, but this command does not work:
go get github.com:capotej/groupcache-db-experiment.git
The repository is hosted on GitHub. What is the correct way to install or download this package with go get?
Short Answer
By the end of this page, you will understand how go get identifies Go packages, why GitHub repository paths must use Go import path format instead of Git clone syntax, and how to correctly fetch packages from GitHub in Go projects.
Concept
In Go, go get works with package import paths, not raw Git repository URLs.
That means Go expects a path like this:
github.com/user/repository
not this:
github.com:user/repository.git
The second format looks like a Git SSH-style repository address, which is valid for git clone, but not for go get.
Why this matters
Go tools are designed around import paths. These paths tell the Go toolchain:
- where the code lives
- how to download it
- how to refer to it in your source code
For example, if your code imports:
import "github.com/capotej/groupcache-db-experiment"
then the matching go get command is:
go get github.com/capotej/groupcache-db-experiment
Important context
Historically, go get was commonly used to download code into $GOPATH. In modern Go, projects usually use Go modules, and dependencies are stored in the module cache instead of being manually managed in $GOPATH.
Mental Model
Think of go get like asking Go for a book by its library catalog name, not by the warehouse shipping address.
- Import path = the catalog name Go understands
- Git URL = the shipping or transport address used by Git
If you ask the Go tool using the wrong naming system, it cannot find the package correctly.
So:
github.com/capotej/groupcache-db-experiment✅github.com:capotej/groupcache-db-experiment.git❌
Go wants the package name in its own ecosystem's format.
Syntax and Examples
The basic syntax is:
go get package/import/path
Correct example
For the repository in your question, use:
go get github.com/capotej/groupcache-db-experiment
Why this works
This is the correct Go import path format:
- domain name first
- then username or organization
- then repository name
Example in code
If a package exposes code you want to use, your import might look like this:
package main
import (
"fmt"
_ "github.com/capotej/groupcache-db-experiment"
)
func main() {
fmt.Println("package fetched successfully")
}
The blank identifier _ import means the package is imported only for side effects. In normal code, you would usually import and use exported functions or types.
Modern module-based workflow
Inside a Go project, you would typically run:
mod init example.com/myapp
get github.com/capotej/groupcache-db-experiment
Step by Step Execution
Consider this command:
go get github.com/capotej/groupcache-db-experiment
Here is what happens conceptually:
1. Go reads the import path
Go sees:
- host:
github.com - owner:
capotej - repository:
groupcache-db-experiment
2. Go resolves the repository
The Go tool determines where the source code is hosted and how to fetch it.
3. Go downloads the code
Depending on your Go setup:
- older GOPATH mode: code is placed under
$GOPATH/src/... - module mode: code is stored in the module cache
4. Go records dependency information
In module mode, go.mod and possibly go.sum are updated.
5. Your code can import the package
You can then use the same import path in Go source files:
import "github.com/capotej/groupcache-db-experiment"
Wrong command trace
Real World Use Cases
Using go get or Go dependency fetching is common in many practical situations:
Adding a library to an API server
You may want to use a router, logger, or database driver:
go get github.com/gin-gonic/gin
Installing a CLI dependency in a project
A project may need a package for configuration, validation, or parsing:
go get github.com/spf13/viper
Pulling code used by internal tooling
Build scripts, deployment tools, or data migration tools often depend on external packages.
Downloading code from source control consistently
Using import paths gives teams a stable, language-native way to reference dependencies across machines and environments.
Real Codebase Usage
In real Go projects, developers usually do not think in terms of manually filling $GOPATH. Instead, they work with modules and let Go manage dependencies.
Common patterns
Add a dependency from inside a module
go mod init example.com/myapp
go get github.com/sirupsen/logrus
Import what you use
import "github.com/sirupsen/logrus"
Keep dependency definitions in versioned files
Real projects commit:
go.modgo.sum
This makes builds reproducible.
Use package paths consistently
The path used in go get should match the path used in import.
Related development patterns
- Validation: ensure the package path is correct before assuming installation failed
- Configuration: module mode is controlled by project structure and Go environment
- Error handling: if fetching fails, developers check path spelling, repository visibility, and module compatibility
- first verify whether the package path is a Go import path or only a Git clone URL
Common Mistakes
1. Using a Git URL instead of a Go import path
Broken:
go get github.com:capotej/groupcache-db-experiment.git
Correct:
go get github.com/capotej/groupcache-db-experiment
2. Adding .git unnecessarily
Broken:
go get github.com/user/project.git
Correct:
go get github.com/user/project
Go usually wants the import path, not the repository suffix.
3. Confusing GOPATH mode with module mode
Beginners often expect all downloaded code to appear directly inside $GOPATH/src. In modern Go, dependencies are usually handled through modules.
4. Using the wrong import path in code
If you fetched:
go get github.com/capotej/groupcache-db-experiment
then your import should match that path exactly.
5. Assuming every GitHub repository is a usable Go package
A repository may:
Comparisons
| Concept | Example | Used By | Correct for go get? |
|---|---|---|---|
| Go import path | github.com/capotej/groupcache-db-experiment | Go toolchain | Yes |
| Git SSH-style URL | github.com:capotej/groupcache-db-experiment.git | git clone in some contexts | No |
| HTTPS Git URL | https://github.com/capotej/groupcache-db-experiment.git | Git | Usually not the normal go get form |
GOPATH mode vs module mode
| Mode | Dependency location |
|---|
Cheat Sheet
go get github.com/user/repo
Rules
- Use the Go import path
- Do not use
:aftergithub.com - Do not add
.gitunless documentation specifically requires something unusual - The path used in
go getshould usually match the path used inimport
Correct
go get github.com/capotej/groupcache-db-experiment
Incorrect
go get github.com:capotej/groupcache-db-experiment.git
Remember
go getis for Go package pathsgit cloneis for Git repository URLs- modern Go usually uses modules instead of manually managing
$GOPATH
Quick check list
- Is the host correct?
- Is the username or org correct?
- Is the repository name correct?
FAQ
Why does go get github.com:... fail?
Because that is Git-style syntax, not a Go import path. go get expects github.com/user/repo.
Should I include .git in a go get command?
Usually no. Go package paths normally do not include .git.
Does go get install code into $GOPATH?
In older GOPATH workflows, yes. In modern Go, dependencies are usually stored in the module cache and tracked in go.mod.
What is the correct command for this repository?
go get github.com/capotej/groupcache-db-experiment
Can I use git clone instead of go get?
Yes, but that solves a different problem. git clone copies the repository, while go get works with Go dependency management.
Why must the import path and fetch path match?
Because Go uses the import path as the package identity. Consistent paths help the toolchain locate and build dependencies correctly.
Mini Project
Description
Build a tiny Go program that imports an external package using the correct Go import path format. This project helps reinforce the difference between a Go package path and a Git repository URL.
Goal
Create a Go module, add an external dependency with go get, and run a program that uses it successfully.
Requirements
- Create a new Go project folder.
- Initialize the project as a Go module.
- Add an external package using
go getwith the correct import path format. - Write a small program that imports and uses the package.
- Run the program successfully.
Keep learning
Related questions
Automatic Build Versioning in Go: Embed Incrementing Build Numbers
Learn how to add automatic build versioning in Go using linker flags, build metadata, CI counters, and Git-based version values.
Blank Identifier Imports in Go: What `_` Means in an Import Statement
Learn what `_` means in a Go import, why blank identifier imports run package init code, and when to use them safely.
Calling Functions Across Files in the Same Go Package
Learn how Go uses packages across multiple files, why functions may appear undefined, and how to organize code correctly.