user234562
user234562

Reputation: 627

Git Alias - git commit with branch name

I want to have one git alias to commit a message and auto filling the branch name in the commit message. output example: git commit -m "[EX-1234] This is the commit message"

I am looking for a way to only type in the terminal: git cm this is the commit message and it will execute the output example.

Things I have tried

cm = "git commit -m \'[$(current_branch)] ${1}\'"
cm = "!f() { \
         git commit -m '[$(current_branch)] $1'; \
       }; f"
cm = '!sh -c '\''git commit --m  "${1}"'\'' -'

The above examples dont work

Upvotes: 2

Views: 886

Answers (1)

IronMan
IronMan

Reputation: 1960

Use $@ to propagate all the arguments to the underlying command, as in:

cm = "!f() { git commit -m "[$(current_branch)] $@"; }; f"

Upvotes: 4

Related Questions