Golang as a very strict directory hierarchy on which the builder (and more generally the Go tools) rely on.
I am often asked what is the proper way to contribute to a Go project.
- Contributing to a random Go project
- Working as a team on a “central” repository
- Contributing to a Go project with sub-repositories
The issue is that when you
go get a project, it ends up in (with github)
If you fork the project, you will have
go get that forked URL, it will work fine. However, if you are dealing with a library that needs to be imported, then you need to update the import paths. Even worse, if the project has sub-repositories, then all import paths will target the original project.
Use your fork only as remote placeholder, do not use it locally. Use the remote feature of git.
Example for user
gcharmes trying to contribute to
- Fork the project
- get the original one
go get github.com/creack/termios
- Add the new remote:
git remote add gcharmes email@example.com:gcharmes/termios.git
- Fetch everything from github
git fetch --all
- Checkout in a new branch
git checkout -b mybranch
- Contribute, as we are on the original checkout, all the paths are correct
- Commit and push
git commit -p && git push gcharmes mybranch
- Go to github and create the pull request.
That’s it! This work if you want to fork a project and use it transparentely, it works when working on sub-packages, it works everywhere :)
Extra tip: use Godeps (https://github.com/tools/godep). When using external dependencies, you should vendor them. It as also the advantage to backup your local version, so if you submitted a PR that didn’t get accepted yet, you still can commit to your own project using your commit for that dependency.