DEV Community

Oleksiy Rudenko
Oleksiy Rudenko

Posted on

Git backed package management

As a developer I want to keep my code base DRY and also DRO1 as much as only possible. To achieve that I want to be able to

  • import a 3rd-party package
  • update imported package from its source

There are package and dependency managers that come to rescue. npm and yarn in JavaScript Universe, and Composer often attributed to PHP World to name a few.

But what if your technology stack ecosystem doesn't offer any (BTW, did you know you can effectively use either of the above in virtually any ecosystem?) or only tools you can (or may) employ are Ctrl-C/Ctrl-V2 and/or git?

Copy-pasting is the latest resort. Let's stick to git.

Many employ the following git-based tools:

Well, the above works. But recently I found a tool that not only removes hassle but also allows to push changes to imported packages back to source (consider pull-request mechanism though).

Here is the hero of the day!

git-subrepo

Basic workflow is as simple as

# init
git subrepo clone anotherRepo.git localSubdir4anotherRepo -b master
# update from anotherRepo
git subrepo pull localSubdir4anotherRepo
# export back
git subrepo push localSubdir4anotherRepo -b anotherRepo-target-branch

I just love it.

More details and further reading on the topic available in Repo import and export back gist.


(1) - Don't Repeat Others; arguable but IMO perfectly fits the context here.

(2) - or equivalent supporting content copy-pasting.

Top comments (0)