As I’ve started to use more OSS Golang libraries, I’ve also struggled to figure out how to handle the fork and PR process in light of Go’s use of specific repos in import statements. This was a bit of great advice given by Zac Bergquist, and I wanted to capture this for myself, and share it with others who will inevitably need to figure out how to do the same when they want to submit a pull request against a Go project.
If you are forking with the intention of pushing upstream you should not update the import paths. Instead fork it but don’t clone your fork. Fork it, go get the original, and then add a remote that points to your fork.
Here are the exact steps I took to follow Zac’s advice as part of a PR I want to submit to the go-cfclient library:
- Fork the repo on Github
- Clone the original:
go get -d github.com/cloudfoundry-community/go-cfclient
- Add the remote that points to my fork:
git remote add fork https://github.com/dave-malone/go-cfclient.git
Now you can simply make changes to the code under
~/go/src/github.com/cloudfoundry-community/go-cfclient and add and commit locally. As you work, simply push your changes to your fork using
git push fork master. Finally, submit your PR, and hope it gets merged into the original project.