Search code examples
gitaliases

git alias taking all given arguments


What I've been trying to do is make a git alias so that git heroku Fix that bug will run:

git add .
git commit -m "Fix that bug"
git push heroku master

This is what I've tried so far:

heroku = "!f() { git add .; git commit -m \"$@\"; git push heroku master; }; f"

seems to have been the most promising so far, though with this if I do git heroku test test, it tells me that error: pathspec 'test' did not match any file(s) known to git.

I've also tried some other ones like !sh -c 'git add ...' - but that didn't work too well either.

Anyone know how to fix this? (and why that message is occuring)


Solution

  • I strongly recommend you pass the log message as a single, quoted string. Even though you could get way with a list of unquoted words in most cases using

    git commit -m "$*"
    

    eventually you will try to use a commit message like

    git heroku Replace * with #
    

    and you're going to get a list of file names in your commit message. Just get used to

    git heroku "Replace * with #"
    

    and define your alias as

    heroku = '!f() { git add .; git commit -m "$1"; git push heroic master; }; f'