guanchor
guanchor

Reputation: 97

Is git-subtree appropriate for me?

I have a 3rd party library included in my project. It is important that the "subproject" code should be included in the main/parent one, because the objective is when other people makes git pull, they could will download the code with no extra-effort (or minimal).

But I want the possibility to download updates from the library own repo.

Previously, that library was downloaded directly into his directory and updates were managing by commits in the main project.

Now I'm thinking in use git-subtree or git-submodule. Is git-subtree are useful for that purpose. Is git-submodule better?

Upvotes: 1

Views: 665

Answers (2)

johnb003
johnb003

Reputation: 1909

Git subtree.

  • Easy for others to get.
  • Avoids complications if you DO want to make changes to the library.
  • Use the squash option to avoid pulling in massive histories when merging the library.
  • You can merge the library, using the git subtree command, and no one else needs to have support for the command to access and use your repository.
  • Changes made in your repository inadvertently to the library are no problem, and simply to split out if you want to contribute them.

Upvotes: 1

acjay
acjay

Reputation: 36671

Almost always, it's best to use the package manager of whatever language you're using to include third-party code, pinned to a specific version. If you don't have a package manager, pull the code from a specific commit/tag of the third party repo in a build script into a git-ignored subfolder.

But to answer your question specifically, there are a lot of resources out there to compare subtree and submodule. There are pros and cons each way. I could give you links, but I'd just be copying and pasting from my search. I would suggest that for code you're not directly changing as part of your project, a submodule is fine, because you probably don't want the history of the library code in your project.

Upvotes: 1

Related Questions