Skip to main content
Using Git

Push an Empty Commit in Git

Yes, you can totally push an empty commit in Git if you really want to. Here's how to do that.

β€” Sagar Sharma

Warp Terminal

While it sounds ridiculous to push an empty commit in Git, there are several reasons why one would want to do so such as marking a checkpoint.

The best part is Git allows you to push an empty commit without any trick as all you have to do is use the --allow-empty flag while committing:

git commit --allow-empty -m "The empty commit"

Then you can push it to the main branch:

git push origin master

Want more details? I got you πŸ˜‰

Pushing an empty commit in Git

Most Git users are already aware of how to commit a file in Git you may get confused as if you don't stage any file and try to commit it, then it will tell you "nothing to commit":

unable to commit empty in git

To push an empty commit in Git, you have to use the --allow-empty flag with the git commit command as shown here:

git commit --allow-empty -m "Your message"
Push empty commit in git

Once you are done with the commit, you can push it to the master remote:

git push origin master
push empty commit in git

There you have it!

Want to learn Git from scratch? Hear me out!

If you are new to Git, then you can start by learning how to create a new branch in Git:

Create a New Branch in Git
In the Git Beginner’s tutorial, learn how to create a new branch.

Furthermore, if you want to do the same but on GitHub, then, here's how to create a new repository in GitHub:

How to Create a new Repository in GitHub
In this primer on GitHub, learn to create new repositories. It also answers a few common doubts that arise while creating GitHub repositories.

Finally, here are some tips for setting up an effective GitHub student profile:

7 Tips to Make a Rockstar Student Developer GitHub Profile
Time to enhance the look and feel of your boring default GitHub profile with these tips and suggestions.

Let me know what else should I cover from the Git side.

Sagar Sharma