DEV Community

Cover image for Setting up VSCode to write commit messages like a boss
crespire
crespire

Posted on • Edited on

Setting up VSCode to write commit messages like a boss

So you've got your shiny code all ready to push up to remote, and you're about to write a commit message.

I am sure you've heard all the tips about writing excellent commit messages, like making sure the title is only so long, that the body is only x characters per line and all that fun stuff. Did you know that you can use VSCode to make your commit messages?

First, configure VSCode as the default editor for git:

git config --global core.editor "code --wait"

This command sets git to open up VSCode when you type git commit without passing in a -m "message" so that you can provide more context about your commit message. The --wait part just tells git to wait until the user closes the file before moving on.

Now, when you type git commit without -m, you'll see a file open in your VSCode called COMMIT_EDITMSG and git will wait until that file is saved and closed before continuing.

Second, we can actually set up some rulers to help you make sure you stay within the recommended formatting! You'll want to open up your settings.json and insert these lines:

"[git-commit]": {
        "editor.rulers": [50, 72],
    },
Enter fullscreen mode Exit fullscreen mode

This will add two rulers to the editor that will open for any git commit! The ruler is the 50 character limit for the title and the second is the 72 character limit for the body of the commit.

That's it, now you can write all the commit messages you want and know that they will render properly!

Top comments (0)