How to update Go dependencies [duplicate]

Solution for How to update Go dependencies [duplicate]
is Given Below:

the go mod tidy adds package dependencies to the go.mod file. How we can update them automatically without manually editing go.mod file, e.g. by removing some entries? For instance, if I use make I want to add a similar command that can update all dependencies of my package/repo and then compile the code with latest version of package dependencies.

In order to update all the dependencies you need to use:

go get -u

And then go mod tidy.

go get -u updates all packages and their dependencies, changing the go.mod.