A terminal app that lists the dependencies of a Go module, shows which ones have newer versions, and upgrades the ones you pick in a single step.
go-upgrade example.com/demo
3 direct · 2 indirect · 4 updates · 2 marked
Direct dependencies 3 updates
[ ] github.com/google/uuid v1.3.0 → v1.6.0
› [x] github.com/spf13/cobra v1.7.0 → v1.10.2
[x] golang.org/x/text v0.14.0 → v0.42.0
Indirect dependencies 1 updates
[ ] github.com/inconshreveable/mousetrap v1.1.0 up to date
[ ] github.com/spf13/pflag v1.0.5 → v1.0.10
↑/↓ move · space mark · a all · d direct · n none · enter upgrade · o open repo · h hide up to date · r reload · q quit
go install github.com/mdogan/go-upgrade@latestIt needs the go command on your PATH.
go-upgrade [flags] [dir]Run it in a directory that has a go.mod file, or pass the directory as an
argument. Without flags it opens the interactive list.
The list shows the modules required in go.mod in two groups: direct and
indirect (the ones marked // indirect). The list appears right away, and
the update column fills in once the check for newer versions is done.
In the update column:
- green: a new patch version (
v1.2.3 → v1.2.4) - yellow: a new minor version (
v1.2.3 → v1.3.0) (retracted): the author has retracted the version you use(deprecated): the author has deprecated the module
| Key | Action |
|---|---|
↑ ↓ / k j |
Move up and down |
PgUp PgDn, g G |
Move by half a page, jump to the top or bottom |
Space |
Mark or unmark the module, then move down |
x |
Mark or unmark the module, the cursor stays |
a |
Mark all modules that have updates (press again to clear) |
d |
Mark only direct modules that have updates (press again to clear) |
n |
Clear all marks |
Enter / u |
Upgrade the marked modules (asks [y/N] first) |
o |
Open the repository of the module in the browser |
h |
Hide or show modules that are up to date |
r |
Read go.mod again and check for updates |
q / Esc / Ctrl+C |
Quit |
Use these to skip the interactive list, for example in scripts or CI:
| Flag | Action |
|---|---|
-list |
Print the dependencies and their updates, then exit |
-direct |
Print the list, then upgrade all direct dependencies |
-all |
Print the list, then upgrade all dependencies |
go-upgrade uses the go command for all the work:
go mod edit -jsonreads the required modules fromgo.mod.go list -m -u -json <modules>finds the newest version of each one.- For the upgrade, a single
go get mod1@v1.2.0 mod2@v0.5.1 …sets every marked module to the version shown in the list. Thengo mod tidyruns. If the module has avendor/directory,go mod vendorruns as well.
To find the repository for o, go-upgrade reads the Origin field from
go mod download -json mod@version. This also works for vanity paths like
golang.org/x/mod. If that fails (for example, the proxy doesn't report the
origin), it guesses the address from the module path, or opens the module's
page on pkg.go.dev.
After an upgrade the app shows the output of these commands and checks for updates again.
- New major versions are not shown. A new major version (for example
v2) has a different module path (example.com/foo/v2), sogo list -udoes not report it. Moving to it means changing your imports. - Other modules can change too. When you upgrade one module,
go getalso raises the modules it needs to their minimum required versions. Thegoline ingo.modcan go up too, if a new version needs a newer Go. - Replaced modules (
replacedirectives) are listed like any other module. Upgrading one changes itsrequireline, but thereplacestill decides which code is used.