Search code examples
gitcommit-message

How to auto-accept git's default commit message?


My git workflow goes like this:

git add . 
git commit 
git push

I would like to know if there are git commands that let me accept the autogenerated commit message (after removing the # of course). The closest answer I've found is this, but it gives me the error:

Aborting commit due to empty commit message.

I can probably change my editor in .gitconfig to a python script that accomplishes this but I'd like to not do that as it will be a system-wide change.


Solution

  • Yes, there is such an option to git commit, --allow-empty-message. That will bypass this check and allow you to make a commit without making a meaningful change to the commit message.

    However, as many people have mentioned in the comments, this is not, in general, a good idea. In almost all cases, you will want to provide a helpful message both for other project participants as well as future you. Unless you are writing an automated script, providing a helpful commit message is a best practice.

    If your particular case is that you don't want to write a commit message for a merge, then simply set GIT_MERGE_AUTOEDIT=no in the environment and Git won't prompt for one.