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](/assets/images/warp-terminal.webp)
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](https://linuxhandbook.com/content/images/2024/02/unable-to-commit-empty-in-git-1.png)
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](https://linuxhandbook.com/content/images/2024/02/Push-empty-commit-in-git.png)
Once you are done with the commit, you can push it to the master remote:
git push origin master
![push empty commit in git](https://linuxhandbook.com/content/images/2024/02/push-empty-commit-in-git.png)
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:
![](https://linuxhandbook.com/content/images/2022/09/create-branche-in-git.png)
Furthermore, if you want to do the same but on GitHub, then, here's how to create a new repository in GitHub:
![](https://linuxhandbook.com/content/images/2023/10/github-create-new-repositories.png)
Finally, here are some tips for setting up an effective GitHub student profile:
![](https://linuxhandbook.com/content/images/2024/01/best-practices-for-rockstar-student-developer-profile.png)
Let me know what else should I cover from the Git side.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.