GitHub and Go: forking, pull requests, and go-getting

an octopher!
During the Go bootcamp that took place in Los Angeles some days ago ( someone asked me a very interesting question.

Question: how do you handle pull requests from different GitHub repositories?

The question seemed pretty simple to answer: you fork the project, then you do "go get" of the fork.
That answer is simple, but incorrect! If you know why ... well, then just go to the answer below.

It is incorrect, because if you fork a repository that has import statements referring to itself, they will be broken in the fork.

Before it gets more complicated let's make this a bit more concrete. You want to send a pull request to fix my awesome project cooltool in

First step is to fork the repository, which creates Easy!

Then you download the source code of the fork using "go get", this will put all the code from the repository in $GOPATH/src/

$ go get

Interestingly enough that also downloads Why?

Well, let's see the contents of

Do you see that? The import path refers to!

You could change it to refer to, but then you would run into conflicts when you send the pull request.

Answer: forks and remotes

There's a very simple solution to this problem consisting in three simple steps.

First fork the repository, as before this will create a

Then let's get the original code using go get. Yes, the original instead of the fork.

$ go get
$ git remote add fork

This added your fork as a remote, which means that once you've modified some files and committed the changes you can now run:

$ git push fork


GitHub is a great place to have your code and ,once you know how, sending pull requests for Go repositories is trivial!