Go get workflow for forked repo
I am using
apex and have installed it with
go get github.com/apex/apex/cmd/apex. I have
$GOPATH/bin/apex which works great. I wanted to make some contributions to apex, so I forked it and ran
go get github.com/ajcrites/apex/cmd/apex. So far so good.
The problem comes when I want to actually test my local changes to the project. There are three issues I can see:
go buildlocally doesn’t work because the
main.gofile imports directly from
$GOPATH/src/github.com/apex. I need it to import from
$GOPATH/src/github.com/ajcritesfor the purposes of testing
main.gomanually to import from
ajcritesis wonky since I can’t/shouldn’t commit these changes. Moreover even though it does build with my files — I can tell because it lints them — the binary that is emitted doesn’t work at all.
/apexand building that way does work, but there are two issues:
- The file system directory doesn’t match the actual repo name which is weird
- I still want to be able to use the actual binary from
/apexwithout clobbering it just for the purposes of testing local changes
Is there a recommended way to clone forked
go repositories and build/test locally?
2 Solutions collect form web for “Go get workflow for forked repo”
If you don’t want to change the import paths in your code, or vendor the source in your project, don’t change directory where the code lies in GOPATH. If you want to change the import path, you will need to rewrite that in all the source, or you end up importing multiple versions of the package.
Go into the
$GOPATH/src/github.com/apex/apex directory and change the
origin remote to your forked repo. By convention, I also add the original repo as an
upstream remote, so I can conveniently fetch and merge changes from there as well.
Since vendoring is enabled by default since go1.6, you can put the source in a
vendor/ directory under your control, and make your modifications there. Using git submodules can also allow you to keep it under separate version control, but linked to your project.
Here’s the flow I recommend and use for managing the Gorilla organization on GitHub:
$ go get github.com/gorilla/csrf $ cd $GOPATH/src/github.com/gorilla/csrf # Alternatively, you can git remote remove origin + re-add as SSH $ git remote add elithrar email@example.com:elithrar/csrf.git $ git checkout -b new-feature-X $ <do some work on it> # Install those changes. $ go install ./...
That’s it. No need to change import paths in any existing programs. If you’re vendoring the dependencies, you can just change it in the vendored copy.