2

I am using third party packages in golang and I want to add them to my git repository and when I type the command git add . it is giving me the following error

warning: adding embedded git repository: github.com/beorn7/perks
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> github.com/beorn7/perks
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached github.com/beorn7/perks
hint: 

How to make sure that I am version controlling packages correctly and Am I doing the right way of version controlling my third-party packages?

Here is my project structure

Project/
|
src/
  |
   github.com/
      |
      packages/

My GOPATH is also pointing to project directory

1
  • Use the standard go dep tool. Don't fight the tools. Commented Oct 21, 2018 at 13:46

1 Answer 1

2

From what I understand you don't use any package manager, instead you import packages to your $GOPATH. I would advise you to use package manager like dep which builds vendor directory containing all dependencies. When you run dep ensure it will go through your code and pull all the dependencies automatically.

Edit: As @jubobs since go1.11 you can use go mod. Basic premise is the same as dep.

Sign up to request clarification or add additional context in comments.

5 Comments

No mention of Go 1.11 modules?
@xReprisal, Thanks for the reply, I did try to use dep but I get the following error when I run dep init "init failed: unable to determine the import path for the root project Project/src: dep does not currently support using GOPATH/src as the project root"
@xReprisal, if I use dep and what happens if the third party package owner deletes the repo. How will dep download the package if I want to use my project in another version?
I think dep did not work because you have your project inside Project/ which is also $GOPATH. Go has very clear guideliness as to how structure your projects. Each project at the very least should reside inside Project/src folder.
If you are afraid of packages being deleted then you can download them to your $GOPATH and then manually create vendor folder by copying them inside for each of your project. Though I would strongly advise against that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.