I use a function for convenience. It works for my coding style, which for me means always working in a clean directory at the repo root and accessing all files with a relative path. YMMV.
qp() {
[[ -z "$1" ]] && echo "Please enter a commit message:";
typeset msg="$( [[ -n "$1" ]] && echo "$*" || echo $(head -1) )";
date;
git pull;
git add .;
git commit -m "$msg";
git push;
date
}
Call it like -
qp add a commit message
Note that it flattens all arguments into a single msg, and if it gets none it prompts for one.
$: qp
Please enter a commit message:
foo bar baz
Tue, Mar 19, 2019 3:25:24 PM
Already up-to-date.
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
Everything up-to-date
Tue, Mar 19, 2019 3:25:31 PM
What you asked for:
Rewrite it to take a file list and always ask for the message, like this:
qp() {
echo "Please enter a commit message:";
typeset msg="$( head -1 )";
date;
git pull;
git add "$@";
git commit -m "$msg";
git push;
date
}
You can just put the function code into a script with or without the function as you prefer.
- NOTE: you might prefer
cat to head -1 to allow multiple lines, but you will have to terminate your message with a CTRL_D or some such.
Then run it as
qp file1 file2 fileN
and it will ask for the commit message - OR, make the first argument the commit message, like this:
qp() {
typeset msg="$1";
shift;
date;
git pull;
git add "$@";
git commit -m "$msg";
git push;
date
}
Just make sure you "quote" that first commit message argument. ;)
qp "here's my commit message" file1 file2 fileN
git add <files>/commit_and_push "message goes here". I'm not sure that scripting this is very beneficial../script.sh "sample message"