go modules

GOPATH is dying, better switch to modules soon, so how can you make it work with just a git (no http(s))?

ssh setup

make ssh work automatically, ie ssh ~/.ssh/config:

    User arccy                      # assuming you don't use a generic git user
    Port 443                        # assuming you use nonstandard port
    IdentityFile ~/.ssh/id_ecdsa_sk # ssh keyzzzz

git setup

make git always use ssh, and point it to your home directory. ~/.gitconfig:

[url ""]
    insteadOf = "git://"
    insteadOf = ""


create a dependency!

$ mkdir -p ~/tmp/hello && cd ~/tmp/hello

$ go mod init

$ cat << EOF > hello.go
package hello

var Hello = "world"

create a git repo on the remote

$ ssh git init --bare hello -b main
Initialized empty Git repository in /home/arccy/hello/

create a git repo locally and push to remote

$ git init -b main
Initialized empty Git repository in /home/arccy/tmp/hello/.git/

$ git add .

$ git commit -m "init"
[main (root-commit) 02adee5] init
 1 file changed, 3 insertions(+)
 create mode 100644 hello.go

$ git remote add origin

$ git push -u origin main
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 240 bytes | 240.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.


Now to use the dependency

$ mkdir -p ~/tmp/world && cd ~/tmp/world

# you may want to persist this setting with go env -w GOPRIVATE=...
$ export

$ go mod init example/world
go: creating new go.mod: module example/world

$ cat << EOF > main.go
package main

import (

        "" // use .git to tell Go about repo root

func main() {

$ go mod tidy
go: finding module for package
go: downloading v0.0.0-20210329200831-02adee55f661
go: found in v0.0.0-20210329200831-02adee55f661

$ go run .