My team always includes Jira ticket numbers in our commit messages to track changes back to specific issues. Right now we type these manually which leads to mistakes and typos.
Since our git branch names already contain the Jira ticket ID, I’m wondering if there’s a way to automatically pull that number into the commit message field in VS Code.
Is this possible using a VS Code plugin or maybe through git commit templates? It would save time and reduce errors if the commit message box could pre-fill with something like the branch name or extract just the ticket number from it.
Has anyone set up something like this before? What approach worked best for your workflow?
I’d try GitLens with commit message templates. Set up VS Code workspace settings with a custom template that pulls from your current branch name. You can use variables like ${workspaceFolder} and write a quick script to grab ticket numbers from branch names. Unlike git hooks, this only affects VS Code users - no server-side setup needed. I usually create a keybinding that auto-fills the commit input with the ticket number. Takes some initial setup per project, but once it’s done it works great with VS Code’s source control panel.
I’ve been doing this with git hooks for two years - works like a charm. Set up a prepare-commit-msg hook that pulls the ticket number from your branch name and adds it to your commit message automatically. Just create a prepare-commit-msg file in .git/hooks and make it executable. Use regex to grab patterns like ABC-123 or PROJ-456 from the branch name. Best part? It works with any editor or commit interface, not just VS Code. Once it’s running, every commit gets the ticket number without you lifting a finger. Just make sure everyone on your team uses consistent branch naming or it’ll break.
i’ve tried that too, but using a commit template feels a bit clunky for me. instead, check out some extensions for vs code that can help automate this. they can make life a bit easier and faster for adding those ticket numbers!