Forking Go libraries with the intent of submitting a Pull Request

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.

Per Zac:

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:

  1. Fork the repo on Github
  2. Clone the original: go get -d github.com/cloudfoundry-community/go-cfclient
  3. Add the remote that points to my fork:

    cd ~/go/src/github.com/cloudfoundry-community/go-cfclient
    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.

Resources:

  • https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.