Is it possible to use a commit message from stdout, like:

echo "Test commit" | git commit -

Tried also to echo the message content in .git/COMMIT_EDITMSG, but then running git commit would ask to add changes in mentioned file.

2 Answers 2


You can use the -F <file>, --file=<file> option.

echo "Test commit" | git commit -F -

Its usage is described in the man page for git commit:

Take the commit message from the given file. Use - to read the message from the standard input.

  • 1
    Missed this option while reading man :) Thanks!
    – fugitive
    May 21, 2017 at 19:57

You could always write a little function for it:

    read message
    git commit -m "$message" "$@"

Add that to your ~/.bashrc or equivalent for your shell, and then run:

echo "Test commit" | gcm filename.to.commit

The command above will run

git commit -m "Test commit" filename.to.commit
  • 1
    I think you meant echo "Test commit" | gcm filename.to.commit. May 22, 2017 at 5:18
  • @user2313067 d'oh! Yes I did, of course. Thanks!
    – terdon
    May 22, 2017 at 8:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .