Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git alias's with arguments that have spaces

Tags:

git

alias

shell

I can't find any examples of git alias's that allow arguments with spaces, here is what I have created:

cax = "!f() { msg=${1-Default message}; git add --all && git commit -am "$msg"; }; f"

This works fine with:

git cax "one-word"

But breaks with:

git cax "one word"

Thanks!

like image 722
Alex Avatar asked Jan 20 '26 11:01

Alex


1 Answers

Did you notice the odd syntax highlighting in your question?

cax = "!f() { msg=${1-Default message}; git add --all && git commit -am "$msg"; }; f"
^^^^^^                                                                   ^^^^         black
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    ^^^^^^^^ red

That should have been a big hint. The problem is that $msg isn't quoted in your function definition. " characters are treated specially by Git when it is reading your config file, but you want to pass these two characters to the shell. Use \"$msg\" instead.