Empty commits play a significant role in enhancing version control workflows. Although seemingly counterintuitive, they offer valuable benefits for documentation, triggering automation. In this short guide, we'll demonstrate how to create and push an empty commit using Git.
Step 1: Initialize a Git Repository
If you haven't already, navigate to your project directory and initialize a Git repository with the following command:
$ git init
Step 2: Create the Empty Commit
To create an empty commit, use the following command:
$ git commit --allow-empty -m "Empty commit"
The --allow-empty flag allows an empty commit, and the -m flag is used to specify a commit message. Feel free to replace "Empty commit" with a meaningful message describing the purpose of the commit.
Step 3: Push the Empty Commit
To push the empty commit to the remote repository, use the command:
$ git push origin <branch-name>
Replace <branch-name> with the name of the branch you want to push the commit to, such as "main" or "develop."
Conclusion:
Empty commits might seem unusual, but they offer significant advantages in managing version control. By documenting milestones, triggering automation processes, and maintaining codebase stability, empty commits can improve collaboration and project management. It is important to note that empty commits should be used specifically in Pull Requests/Merge Requests to avoid cluttering the commit history of the main/production branch.
Latest comments (60)
I hope you have also tried: Automated AI commits maybe more interesting.
Thanks for sharing !
Git is a total mess. One more, one less? Meh.
I have known only few command in git, it was new to me and got some knowledge, thank you
Okay so I am thinking that it is not a good idea to create a empty meaning because a commit name is meant to describe it's change so if you don't do any changes there should not be a commit name so no commit at all.
However, I don't have enough information on why you are using them to trigger CI
I am assuming that you are using GitHub in my recommandation
Awesome
Thank you.
Empty commits are useful in cases where you want to generate builds some change in sub module projects or dependency projects, so that latest build includes those build.
Wish i knew this allow empty flag before making a redundant space to make a ci trigger commit last week. Thanks for sharing.
Can Tagging be another alternative to this..
git-scm.com/book/en/v2/Git-Basics-...
Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more