Published on

How to Import a Golang Forked Repos New Package

Authors

I had to work with a forked Go repo today. The problem is that imports in Go are generally of the form github.com/some-organisation-or-profile/projectname/path/to/required/package where in this case the original repo is hosted on github. In my case I forked this repo so the base repo technically becomes github.com/my-profile/projectname. This means that if I added a new package in my fork I would have to import it as github.com/my-profile/projectname/path/to/new/package. The problem is when this is merged the path should then be github.com/some-organisation-or-profile/projectname/path/to/new/package.

After some Googling I came across this answer. The suggested answers did not work too well as the suggested solutions seem to refer more to a forked repo where no new packages are added. The quickest and easiest was what the person asking the question suggested:

git clone [email protected]:some-organisation-or-profile/projectname.git $GOPATH/src/github.com/my-profile/projectname