AI generated commit messages

November 12, 2022, by Mikkel Bech

Commit messages can be tedious to come up with and I found a better way (for me at least) to do it, so here's how I do git commits by just hitting CMD-enter in VS Code. AI generates the commit message and to be frank, it does a better job than me at it

  1. Install auto-commit with:

    curl -fsSL https://raw.githubusercontent.com/m1guelpf/auto-commit/main/install.sh | sh -
    
  2. add OpenAI API key to .zshrc (or whatever terminal you're using)

    export OPENAI_API_KEY='sk-XXXXXXXX'
    
  3. create a file called auto-push.sh and make sure it's location is in your path

    git add . && \
    auto-commit && \
    git push
    

(if you want to include deletes in your commits as well use git add -A instead of git add .)

  1. Use the "Command Runner" extension in Visual Studio Code" and add this shortcut to preference > keyboard shortcuts:

    {
    "key": "cmd+enter",
    "label": "generate commit and push",
    "command": "command-runner.run",
    "args": {"command": "sh auto-push.sh"},
    "when": "editorTextFocus"
    }
    

Make some changes to your code and hit CMD+enter. Auto-commit will make a suggestion for the commit message and if you're satisfied just hit Y