Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit bash script

Tags:

git

bash

github

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 echos fine) or passing it to git commit -m.

like image 656
mgold Avatar asked Dec 13 '11 00:12

mgold


People also ask

How do I commit in git?

To add a Git commit message to your commit, you will use the git commit command followed by the -m flag and then your message in quotes. Adding a Git commit message should look something like this: git commit -m “Add an anchor for the trial end sectionnn.”

What is git bash script?

Git Bash is an application for Microsoft Windows environments which provides an emulation layer for a Git command line experience. Bash is an acronym for Bourne Again Shell. A shell is a terminal application used to interface with an operating system through written commands.


2 Answers

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.

like image 139
manojlds Avatar answered Oct 01 '22 12:10

manojlds


Here's a merge of the last two answers - chaining together the add -u is awesome, but the embedded read command was causing me troubles. I went with (last line used for my heroku push, change to 'git push origin head' if that's your method):

#!/bin/bash read -p "Commit description: " desc git add . && \ git add -u && \ git commit -m "$desc" && \ git push heroku master 
like image 34
JayCrossler Avatar answered Oct 01 '22 12:10

JayCrossler