It’s been a while since we started to move our build system from grunt to gulp. I will not explain why but if you have worked with both tools you probably know the reason. On his article, Mark Goodyear does a great work showing the advantage of gulp over grunt.

Gulp by itself doesn’t really do much but it’s huge number of plug-ins makes it really easy to plug and play. Gulp uses node.js streams to make its plug and play flow without the need to write any temporary output data.

However, if you have worked with Gulp for some time you will know that not all the times things go as perfect as expected. Sometimes we get some weird behaviours that are mostly due to our lack of understanding on streams (and I have a huge lack on that matter). If you want to know more on streams, I strongly recommend you to take a look at substack’s handbook.

gulp on release

On our release process (for npm packages) we set the goal of having a single gulp task for that. The idea went something like this:

Fortunately there are some good plug-ins that make this goal quite doable:

The trick here is not to find the right plug-ins but to combine them as a stream able to fail when something goes bad.

Once we understood how callbacks work on gulp and managed to put it to work we were still missing one last thing — to be able to push our git changes and sequentially run another task on a single gulp task.

push with gulp-git

With gulp-git plug-in we are only able to run push from git and sequentially run other gulp plug-in if we have git.push on a dedicated gulp task:

If we run $gulp publish we will see something like this in the output:

Please note that the callback done (on the gulp task push) is what allows us to wait for push to finish before running the publish task.

The problem appears if we want to run all these tasks using pipe:

If you have tried this you will know that using git.push on a pipe does not work. git.push is not prepared to be used in a pipe stream. The solution for this could be to run git.push on ‘end’ event.

However, this solution does not work if we want to run a task that depends on the output of push. In this case publish will start before push finishes.

If you don’t mind to have push on a dedicate task you can follow the solution bellow. No need for gulp-git-push.


Because we wanted to run push on a pipe we wrapped git.push into a stream and call it gulp-git-push:

If we now run $gulp release then we meet our goal of having a release task that runs and fails properly:

And that’s the reason for gulp-git-push!

Tiago Lopes Ferreira

Written by

frontend and javascript engineer, blockchain enthusiast ⚡️ food lover 🍙🍣🍍 compulsive reader, and traveler ✈️