Version Control – Best Way to Manage Reusable Classes/Libraries Separately

code-reusegitpersonal-projectsversion control

When coding, I naturally often come up with classes or a set of classes with a high reusability. I'm looking for an easy, straight-forward way to work on them separately.
I'd like to be able to easily integrate them into any project; it also should be possible to switch to a different version with as few commands as possible.

Am I right with the assumption that git (or another VCS) is best suited for this? I thought of setting up local repositories for each class/project/library/plugin and then just cloning/pulling them. It would be great if I could reference those projects by name, not by the full path. Like git clone someproject.

edit: To clarify, I know what VCS are about and I do use them. I'm just looking for a comfortable way to store and edit some reusable pieces of code (including unit tests) separately and to be able to include them (without the unit tests) in other projects, without having to manually copy files. Apache Maven is a good example, but I'm looking for a language-independent solution, optimally command-line-based.

Best Answer

As @jgauffin points out package management really is the way to fly here. But not everything has a package manager. Or other times you just need the sources riding with things.

Specifics are really a function of what platform, thing you want to look at here would be the sorts of features exposed by git submodules or hg subrepos. Both are designed to pull some part of your source repository from an external source. In the case of hg subrepos they don't even need to be HG -- git or svn can be accessed as well.

The real challenge comes in when you want a subrepository but you need to edit some certain files within it.

Related Topic