Git History & Heroku Pipelines

Timo Bleeker August 18, 2020

For many developers, the git history is the one source of truth for the state of a project. A very common command to run is git log, which will show an overview of the commits and the branches they are found on.

This can be useful to quickly figure out whether your code has already been deployed to Heroku. If your Heroku remote is called staging, running git fetch staging && git log staging/master will show you exactly what commits have been pushed to the Heroku branch 👀.

However, it’s important to know that there’s a gotcha here if you’re using Heroku Pipelines to deploy your staging app to production. Heroku Pipelines provides you this awesome little button:

image

Clicking it will promote your staging app directly to production. This is super fast compared to pushing your code with git push production/master, as it will just use the slug from the staging environment. So no build required!

Now, what’s the gotcha I was talking about? While your app has been promoted to production at lightning-speeds, the production git branch has not been updated with your most recent commits. The next time you run git fetch production && git log production/master to figure out what is live on production, you will not get an accurate result.

In this case, the best way to check what code has been deployed is to use heroku releases -r production. This will print a list of recent releases. A deploy will show listed with its commit sha. You can then look up this git sha in your git history to figure out exactly what code is running on production.

I hope that being aware of this little caveat can save you a bit of head-scratching (and/or hair-pulling). Knowing exactly what version your app is running can save valuable minutes or even hours when identifying issues.

Timo Bleeker

Timo Bleeker