-1

How can I automatically add the branch name that I am currently working on to my commits?

For the moment I have to write it down manually each time I commit something:

[v1.2-branch-name] I did something
[v1.2-branch-name] I did something else
[v1.2-otherbranch-name] I did something else that did not mess up my code

I currently use Github Desktop.

WJA
  • 6,676
  • 16
  • 85
  • 152
  • Does this answer your question? [How to add Git's branch name to the commit message?](https://stackoverflow.com/questions/5894946/how-to-add-gits-branch-name-to-the-commit-message) – phd Dec 12 '19 at 14:47
  • https://stackoverflow.com/search?q=%5Bgit%5D+add+branch+name+commit+message – phd Dec 12 '19 at 14:47

1 Answers1

0

If for any reason you don't want to use a hook here, a simple alias could do the trick :

git config alias.cm '!f() { git commit -m "$(git rev-parse --abbrev-ref HEAD) $1"; }; f'

then, assuming your current branch is named v1.2-branch-name just

git cm "My marvelous message"

would in fact create a commit with the following message

v1.2-branch-name My marvelous message
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61