Learn to push an empty commit

Learn to push an empty commit

Today I faced a problem while triggering the delivery pipeline and this article is about the solution to that problem.

Have you ever faced the need to push a commit to a Git branch without changing any files in order to re-run your integration process? If yes then you are landed at the right place, my friend. 😉

TLDR; Create an empty commit

Problem

For continuous integration, we are using Buddy delivery pipelines which allow us to build, test and deploy applications on a single push to a specific git branch. It helps us to reduce the manual overhead of deploying code to the server and handle all the actions automatically.

But today I faced a problem where I needed to re-run my delivery pipeline of a branch without adding any extra space or changing any files in the repository, so I searched for the solution for a while and It turns out that Git is allowing us to push an empty commit without adding any staged files to the branch, by using one option — allow-empty during git commit.

Enough of the problem, let’s jump on to the solution

Pushing a commit with staged files

The above commands will add all unstaged files and add commit and push the code to the master branch, after that our delivery pipeline will be started.

Once the pipeline process fails or you need to run the process again, you will have to push something to the branch but as I mentioned earlier, we will not make any changes to the files, and even then, We will be able to commit the branch with this command.

Pushing empty commit

After the above commands, you can see that the commit has been pushed to your branch and the delivery pipeline will be started.

You learned that you can be able to push an empty commit with the — allow-empty option of git commit. let me know in the comments if there is any other way to do this.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kode with Chirag

Kode with Chirag

10 Followers

Helping others simplify the web development journey by keeping things short