8

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.

zmii
  • 4,123
  • 3
  • 40
  • 64

2 Answers2

10

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] ".
TiK
  • 139
  • 1
  • 5
2

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.

  • 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 04 '18 at 12:26