So you wanna yarn add a dependency from a git repo?

I’m posting this because, even if really basic stuff, I’ve bumped my head with this wall way too many times before successfully managing to accomplish the task: Use yarn add to pull a dependency while using a git repo as the source.

It is, in fact, really simple (though I feel is way to verbose (? ):

yarn add git+ssh://[email protected]:organization/project

You can even specify use a branch or particular commit by adding it at the end, like this:

# To point to a branch:
yarn add git+ssh://[email protected]:organization/project#dev
# To point to a commit we just use the hash (short one is this case):
yarn add git+ssh://[email protected]:organization/project#c8023772

It’s also listed in the official docs: https://yarnpkg.com/lang/en/docs/cli/add/

So, have you ever had to do this? Do you find it useful?

Cherry-picking your way out of trouble

I find cherry-pick to be one of those great underutilized features of git. And maybe that’s good, because it’s mainly used to apply hot fixes.

The way it works is very simple, it just let’s you merge one or more commits from one branch onto another. Awesome, right?

Imagine a situation in which you have two branches, master and payments-refactor.
You’re battling your way out of a thought refactor and suddenly a bug emerges in production, but you find out that you’ve already fixed it during the refactor and have an isolated commit containing the changes. You need to replicate those changes in the master branch and re deploy the app. But copy-pasting, or manually re doing the
changes, is cumbersome and probably even error prone. Well, cherry-pick comes to the rescue. It let’s us replicate that single commit onto the master branch, all while preventing duplicate work and keeping our git history clean.
The only thing we need is the abbreviated commit hash (or all of it), we move to the branch where we want to incorporate the changes and use it like this:

git checkout master
git cherry-pick 3f75a585

That’s all!

I hope you have to use this as little as possible, but find it useful when the time comes.

What do you think of cherry-pick, what do you use it for?