Is there any way I can do
git add -A
git commit -m \"commit message\"
in one command?
I seem to be doing those two commands a lot,
Just combine your commands:
git add -A && git commit -m "comment"
The most simply you can do it is :
git commit -am "Your commit message"
I dont understand why are we making this tricky.
In case someone would like to "add and commit" for a single file, which was my case, I created the script bellow to do just that:
#!/bin/bash
function usage {
echo "Usage: $(basename $0) <filename> <commit_message>"
}
function die {
declare MSG="$@"
echo -e "$0: Error: $MSG">&2
exit 1
}
(( "$#" == 2 )) || die "Wrong arguments.\n\n$(usage)"
FILE=$1
COMMIT_MESSAGE=$2
[ -f $FILE ] || die "File $FILE does not exist"
echo -n adding $FILE to git...
git add $FILE || die "git add $FILE has failed."
echo done
echo "commiting $file to git..."
git commit -m "$COMMIT_MESSAGE" || die "git commit has failed."
exit 0
I named it "gitfile.sh" and added it to my $PATH. Then I can run git add and commit for a single file in one command:
gitfile.sh /path/to/file "MY COMMIT MESSAGE"