Version Control entire GOPATH

723 views
Skip to first unread message

Nick Stogner

unread,
Nov 12, 2016, 12:00:08 PM11/12/16
to golang-nuts
I would like to version control my entire GOPATH to store all of my go code in a monolithic repository. (see http://danluu.com/monorepo/ or https://blog.gopheracademy.com/advent-2015/go-in-a-monorepo/)

The problem that I run into: how to manage dependencies with "go get" ?.. I would like to vendor these dependencies but git wants to treat them as nested repos and doesn't end up vendoring them on commit to the parent repo.

I have tried: moving nested ".git" directories to ".git-moved", etc. This works for vendoring go-gotten repos but is a hassle and also messes up future calls to go get:

$ mv   src/github.com/Sirupsen/logrus/.git   src/github.com/Sirupsen/logrus/.git-moved
$ git add --all; git commit -m 'this commit vendors the logrus package'
$ go
get -u github.com/Sirupsen/logrus
package github.com/Sirupsen/logrus: directory "/tmp/monorepo/src/github.com/Sirupsen/logrus" is not using
a known version control system


I would have to mv those .git-moved directories back to .git before using go-get again and this would be a pain and not scalable to a team.

Has anyone come up with a solution for this?

Hirotaka Yamamoto (ymmt2005)

unread,
Nov 13, 2016, 2:20:24 AM11/13/16
to golang-nuts
We are developing Go programs on a Git mono repository.

To include dependencies, we do not use "go get".
Instead, we import third party packages by using "git subtree".

For instance, github.com/BurntSushi/toml can be imported like this:
    git remote add -f toml https://github.com/BurntSushi/toml
    git subtree add -P go/src/github.com/BurntSushi/toml toml master --squash

To update, just do:
    git fetch toml
    git subtree pull -P go/src/github.com/BurntSushi/toml toml master --squash

This does not work for non-Git repositories, of course.

2016年11月13日日曜日 2時00分08秒 UTC+9 Nick Stogner:

Erik Dubbelboer

unread,
Nov 13, 2016, 3:27:15 AM11/13/16
to golang-nuts
What we do is add all dependencies as git submodules. There is no tool to automate this (as far as I know) so each time you add new dependencies you have to manually 'git submodule add' it and it's dependencies. But after that updating them is as easy as doing a git pull in their directory.

Nick Stogner

unread,
Nov 13, 2016, 5:01:15 PM11/13/16
to golang-nuts
Thanks for the replies! I would like to actually vendor the dependencies to ensure repeatable builds (so I want to avoid submodules).

In a perfect world, I would like to be able to use the go toolchain (not abandon go-get quite yet). I have been able to hack together some client-side git hooks which accomplish this: https://github.com/nstogner/gomono. After installing them in the client repo, the gophers should be able to proceed along without worrying about how they use go-get... Let me know what you think.

Dave Cheney

unread,
Nov 13, 2016, 6:14:09 PM11/13/16
to golang-nuts
Have you considered gb, https://getgb.io/ ? It's purpose built for a project based workflow.
Reply all
Reply to author
Forward
0 new messages