Contributing to projects on GitHub is a great way to learn, contribute, and help make the software you use better. Normally, you would just make a fork of the project and then clone your fork and do your work. Then you would push to a branch in your fork and open a pull request for that branch.
Go is a little different however. Since the imports are specific paths to GitHub/GitLab/etc projects you can’t necessarily just fork the project and do work in your fork.
For example say you are working in a project that has three imports github.com/someproject/cli
, github.com/someproject/api
, and github.com/someproject/tools
.
For your feature you need to make a change in github.com/someproject/tools
, but to do that you also need to add a field to a struct in github.com/someproject/api
. Your imports are always going to be looking for $GOPATH/src/github.com/someproject/
and not including your changes to the other packages. This means your changes in api
won’t show up in your IDE’s function definitions, auto-complete, etc.
Setup
A way to work around this is to actually do the work in the project in the $GOPATH
and then add your fork as a remote to push to. First you would clone the Go project in $GOPATH/src/github.com/theiraccount/someproject/
. Next you would create a branch for your work in this project git checkout -b my-feature
. Now all of your changes should be available in the functions definitions, struct definitions, etc because they are directly in the correct $GOPATH
.
Your Changes
Once your work is done, you add your fork as a remote git remote add myorigin [email protected]:myaccount/someproject.git
. Now you can commit and then push to your fork with git push -u myorigin my-feature
.
Not only does this fix import statements, but also things like tests that would be expecting those values to exist as well.