mgold mgold - 2 months ago 19
Git Question

Git commit bash script

I'm writing a bash script to add, commit, push all files in a directory.

#!/bin/bash
git add .
read -p "Commit description: " desc
git commit -m $desc
git push origin master


I'm getting the following error:

$ ./togithub
Commit description:
test commit script
error: pathspec 'commit' did not match any file(s) known to git.
error: pathspec 'script"' did not match any file(s) known to git.
Everything up-to-date


I'm not sure if this is a problem with reading in the text (it
echo
s fine) or passing it to
git commit -m
.

Answer

You have to do:

git commit -m "$desc"

In the current script, test is going as commit message and commit and script are being treated as next arguments.