10

Is there away to make VS Code automatically prepend branch name in commit message textarea?

Like if I'm on branch 'ID-7345' and just updated e.g. React.js version, I need to write:

ID-7345: updated React.js to version 16.0

and I would like to omit writing branch name each time there, so wherever I access this page I will see ID-7345: pre-populated and cursor blinking after it.

2 Answers 2

11

There is now a VS Code extension that does the job: https://marketplace.visualstudio.com/items?itemName=srmeyers.git-prefix. By default, a click on the extension button will put into your commit message this label: "[YourBranchName]". Into the extension settings, there are 3 parameters if you want to fine tune the label (copy/paste from the extension page):

  • gitPrefix.pattern: Regular expression pattern to match in the branch name. Default matches entire branch name.
  • gitPrefix.patternIgnoreCase: Ignore case in pattern. Default is
    false.
  • gitPrefix.replacement: Regular expression replacement string to place into commit message. Default is "[$1] ".
1
  • Thanks, @Tik for saving a lot of my time. Mar 25, 2022 at 14:43
3

There is nothing to do on VS Code, use this https://git-scm.com/docs/githooks#_prepare_commit_msg or git template. Look at this also, can be helpful.

1
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
    – Paul Karam
    Apr 4, 2018 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.